这是我的情况:
$sql = 'UPDATE user SET password = ? WHERE username = ? AND password = ?';
if($stmt->prepare($sql)) {
$stmt->bind_param('sss', $newPass, $_SESSION['username'], $oldPass);
$stmt->execute();
}
现在,如何查看 UPDATE 查询是否成功执行?更准确地说,我如何查看旧密码和用户名是否正确,以便我可以存储新密码?我试过这样做:
Now, how can I see if the UPDATE query is successfully executed? And more precisely how can I see if the old password and username are correct so that I can store the new password? I've tried by doing this:
$res = $stmt->execute();
echo 'Result: '.$res;
但我总是得到:
Result: 1
即使旧密码不正确.
不更新行的查询不是错误条件.这只是一个没有改变任何东西的成功查询.要查看更新是否确实改变了任何内容,您必须使用 mysqli_affected_rows()
A query which updates no rows is NOT an error condition. It's simply a succesful query that didn't change anything. To see if an update actually did change anything, you have to use mysqli_affected_rows()
这篇关于如何检查 UPDATE mysqli 查询是否正确执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
mysql 中的 store_result() 和 get_result() 返回 falsestore_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
调用未定义的函数 mysqli_result::num_rows()Call to undefined function mysqli_result::num_rows()(调用未定义的函数 mysqli_result::num_rows())
PHP 准备好的语句问题PHP Prepared Statement Problems(PHP 准备好的语句问题)
mysqli_fetch_array 只返回一个结果mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一个结果)
PHP MySQLi 多次插入PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
如何确保 MySQL 中的值在 PHP 中保持其类型?How do I make sure that values from MySQL keep their type in PHP?(如何确保 MySQL 中的值在 PHP 中保持其类型?)