我尝试实现一个注册表单,并尝试通过 php 和 jQuery 检查用户是否已经使用特定电子邮件注册。
这是我的代码:
if(endsWith($email, 'domain.tld'))
{
$result = $database->prepare("SELECT id FROM users WHERE email LIKE ?");
$result->bind_param('s', $email);
//echo $email;
$result->execute();
//echo $result->execute();
//echo $result->num_rows;
//exit();
if($result->num_rows == 0)
{
echo'ok';
}
else {
echo 'duplicate';
}
$result->close();
}
else {
echo 'validation failed';
}
我使用注释的 echos 和 exit() 来调试我的代码。问题是数据库保存用户 user@domain.tld 并且脚本在回显“user@domain.tld10”中显示我。因此该语句执行成功,但没有返回任何行。如果我执行语句
SELECT id FROM users WHERE email LIKE "user@domain.tld"
我得到返回的 ID(在本例中为 11)。
我的问题是,如何更好地调试这个 php 脚本,最大的问题是,为什么我的 scipt 无法正常工作?
提前非常感谢!
最佳答案
在 num_rows 之前使用
$result->store_result();
The use of mysqli_stmt_num_rows() depends on whether or not you used mysqli_stmt_store_result() to buffer the entire result set in the statement handle.
关于php - 调试 mySQLi 准备好的语句 -> 未找到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20457364/