所以这是我在 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();
}
Run Code Online (Sandbox Code Playgroud)
回显 $nrows1 时,我一直返回 0 行或一个空变量。当我直接在sql中输入查询时,它工作正常。我似乎正在关注这些文件并对其进行了大量修改。
我也使用了受影响的行函数,但我认为这不适合 SELECT 语句,对吗?
真诚感谢您的任何帮助,不胜感激。
执行后需要使用mysqli_stmt_store_result()来获取结果集,这样它就会知道有多少行。此外,您应该应用于$num_rows语句,而不是连接。
$stmt->execute();
$stmt->store_result();
$nrows1 = $stmt->num_rows;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1864 次 |
| 最近记录: |