dongqiangou5724
2018-02-11 17:31
浏览 116
已采纳

为什么mysqli_stmt_num_rows函数返回0?

I am trying to create a login page, but I'm having some issues using prepared statements to secure the login. I have the following code:

$sql = "SELECT * FROM users WHERE user_email=?";
$stmt = mysqli_stmt_prepare($db, $sql);
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);

The problem occurs when checking if the result check variable is less than 1. It shouldn't be 0, but it is. I don't understand why, as the database has an email with the value test@test.com, but when trying to enter that the $resultCheck variable still returns 0. I'm guessing it has to do with the prepared statements.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试创建一个登录页面,但是我在使用预准备语句来保护登录时遇到了一些问题。 我有以下代码:</ p>

  $ sql =“SELECT * FROM users WHERE user_email =?”; 
 $ stmt = mysqli_stmt_prepare($ db,$ sql); 
mysqli_stmt_bind_param  ($ stmt,“s”,$ email); 
mysqli_stmt_execute($ stmt); 
 $ result = mysqli_stmt_get_result($ stmt); 
 $ resultCheck = mysqli_stmt_num_rows($ stmt); 
 </ code> </ pre  > 
 
 

检查结果检查变量是否小于1时会出现问题。它不应该是0,但它应该是。 我不明白为什么,因为数据库的电子邮件的值为 test@test.com </ code>,但在尝试输入时, $ resultCheck </ code>变量仍返回0。 我猜这与准备好的陈述有关。 </ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题