php-mysql,更新记录失败但没有错误。
$sql = "UPDATE users SET password='$new_password' WHERE email='$email' AND id='$uId'";
//if ($mysqli->query($sql)) also result in True
if ($mysqli->query($sql) === TRUE) {
$_SESSION['test6'] = $mysqli->error;
$_SESSION['message'] = "Your password have been updated!";
header("location:gain.php");
}
else {
$_SESSION['test7'] = "Error updating record: " . $mysqli->error;
}
我知道它为什么不更新,错误的值在 WHERE
条款。如果值是正确的,它会很好地更新。但无论更新是否成功,当它失败时,任何地方都看不到错误 $mysqli->query($sql)
是 true
.
如何捕捉错误?
我是新来的,我可能应该看看pdo或者它叫什么,但是mysqli不应该给出某种错误吗?这是在xampp本地主机上。
2条答案
按热度按时间gblwokeq1#
您没有收到错误,因为没有错误,您的搜索条件与任何结果都不匹配。如果要获取受查询影响的行数,请使用
affected_rows()
.idv4meu82#