【发布时间】:2019-09-17 01:27:30
【问题描述】:
我正在制作一个带有登录系统的网站。当用户想要注册并输入他的电子邮件时,MySQL 数据库中不应该已经存在一个。我正在尝试通过准备好的语句来编写我的代码。
当用户输入数据库中已经存在的电子邮件时,我希望它通过标题功能将用户发送回相同的注册页面,但出现某种错误。我试图将行数存储在一个名为 $resultcheck 的变量中,并检查是否有列具有超过 0 个相同的电子邮件(如果它已经存在)。
代码如下:
$query = "SELECT * FROM users WHERE Mail=?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $query))
{
header("Location: ../registrering.php?error=sqlerror");
exit();
}
else
{
mysqli_stmt_bind_param($stmt, "s", $mail);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if($resultcheck > 0)
{
header("Location: ../registrering.php?error=emailtaken");
exit();
}
else {...}
但是,当我提交了一个帐户,并且数据库中已经存在电子邮件时,我成功地在表 users 中输入了另一列,并且有多个列具有相同的电子邮件。
【问题讨论】:
标签: php html mysql email-validation