这就是我想知道数据库中存在的用户的方式,但是当它没有这样做时它会不断保持存在。
我想要的是这个代码是为了获取有关数据库中用户的知识,如果它没有明确说明它:)
}
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
}
}
}
我在这里试试:
$email = $_post["email"]
foreach($this->mysqli->query("SELECT * FROM `bruger` WHERE email='$email'") as $row) {
if ($row['email'] !== $email) {
这是我的所有HTML代码:
<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)
{
答案 0 :(得分:0)
查看此算法
POST
数据并清理输入。检查电子邮件
SELECT email
FROM table WHERE email
='$ post_email'LIMIT 1
如果结果不为空,则前进
在db上添加UNIQUE KEY约束
ALTER TABLE <table name >
ADD CONSTRAINT uniqueEmail UNIQUE (< `email column` > )
使用唯一约束将保护您的表,当有人尝试输入重复email
时会出错。所以当您对表执行INSERT
查询时,请检查** mysqli_query **返回的内容(见下文)
$qry = "SELECT INTO table (whatever) VALUE (whatever)";
$done = mysqli_query($qry);
检查$done
,如果一切正常,那么它将返回 TRUE 否则它将提供mysql_error(可能是1064),所以通过这种方式你也可以阻止停止重复的电子邮件地址
答案 1 :(得分:0)
如果您尝试检查电子邮件ID是否存在,此代码就足够了。
$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
}