这是我第一天在MYSQLi工作(从mysql转换过来),我在登录脚本中遇到了一些问题,需要检查重复的电子邮件:
以下是我的代码:
$email = mysqli_escape_string($_POST['email']);
$stmt=$mysqli->prepare("SELECT username from users WHERE email=?");
$stmt->bind_param('s',$email);
$stmt->execute();
$nrows1=$mysqli->num_rows;
echo $nrows1;
$stmt->close();
if ($nrows1>0) {
$_SESSION['loggedin'] = false;
$_SESSION['error'] = "Our records indicate that there is already an account registered with that email. Please use the 'forgot your password' link below if you cannot remember your password.";
header('Location: registration.php');
echo "running insisde duplicate email";
exit();
}
当我输出 $nrows1 时,我得到了0行或空变量。但是当我直接在SQL中输入查询时,它可以正常工作。我似乎遵循了文档并对其进行了一些调整。
我还使用了受影响的行数函数,但我不认为这适用于SELECT语句,正确吗?
非常感谢任何帮助,非常感激。
bind_param
,我认为你不需要转义参数。 - tsnorri