This is how I want to find out about the user exists in the database but it will constantly keep themselves it exists when it does not do it.
What I want out of this code is to get the knowledge about the user in the database if it does not make it must clearly say it :)
}
else
{
$email_1 = $_post["email"];
$result = $this->mysqli->query("SELECT * FROM bruger WHERE email='$email_1'");
if(mysqli_num_rows($resut) > 0)
{
//code here!
}
else
{
?>
<div class="article-main-content">
<div class="alert-message" style="background-color:#c22525;"><span class="icon-text">⚠</span><span class="alert-content">Email Findes på hjemmesiden</span><a href="#" class="destroy-button"></a></div>
</div>
<?php
}
}
}
and i have try its here:
$email = $_post["email"]
foreach($this->mysqli->query("SELECT * FROM `bruger` WHERE email='$email'") as $row) {
if ($row['email'] !== $email) {
here are all my html code:
<form action="#" enctype="multipart/form-data" method="post">
<table width="100%" cellpadding="5" cellspacing="5">
<tr>
<td><p>Email</p></td>
<td><input type="text" name="email" class="ned_input"></td>
</tr>
<tr>
<td><p>Adgangskode</p></td>
<td><input type="password" name="password_adgangskode_1" class="ned_input"></td>
</tr>
<tr>
<td><p>Adgangskode Gentag</p></td>
<td><input type="password" name="password_adgangskode_2" class="ned_input"></td>
</tr>
<tr>
<td><p>Fornavn</p></td>
<td><input type="text" name="fornavn" class="ned_input"></td>
</tr>
<tr>
<td><p>Efternavn</p></td>
<td><input type="text" name="efternavn" class="ned_input"></td>
</tr>
<tr>
<td><p>Profilbillede</p></td>
<td><input type="file" name="file" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="opret" value="Opret bruger" style="margin-top:10px;"></td>
</tr>
</table>
</form>
EIDT HERE
if ($stmt = $this->mysqli->prepare("SELECT `id` FROM `bruger` WHERE `email`"))
{
$stmt->bind_param('s', $email_indhold);
$email_indhold = $_POST["email"];
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id);
$stmt->fetch();
$count = $stmt->num_rows;
$stmt->close();
if($count > 0)
{
look the algorithm for this
POST
data first and sanitize the input.check for the email
SELECT email
FROM table WHERE email
= '$post_email' LIMIT 1
if result is not empty then go forward
to add UNIQUE KEY constraint on your db
ALTER TABLE <table name >
ADD CONSTRAINT uniqueEmail UNIQUE (< `email column` > )
using unique constraint will safe your table,it will give error when someone try to enter duplicate email
.So when you execute INSERT
query for the table, check what**mysqli_query** returns ( see below )
$qry = "SELECT INTO table (whatever) VALUE (whatever)";
$done = mysqli_query($qry);
check $done
, if everything goes fine then it will return TRUE otherwise it will gives mysql_error( may be 1064), so by this way you can also prevent to stop duplicate email address
This code is enough if you are trying to check email id exist or not.
$email_1 = $_post["email"];
$result = mysql_query("SELECT * FROM bruger WHERE email='$email_1' LIMIT 1");
if(mysql_num_rows($resut) > 0)
{
//code here!
//$result contain other column values
}
else
{
//Email id not exist
}