我正在我的 php/mysqli 中进行更新。更新工作正常,但我遇到的问题是我不断收到此警告:
警告:mysqli_stmt::fetch() [mysqli-stmt.fetch]: (HY000/2053): 在第 44 行没有与语句关联的结果集时尝试读取一行。
因为我不断收到此警告,这意味着用户提交表单后,即使输入了正确的用户名,它仍然显示消息“您输入的用户名无效。请尝试再次输入。” 当它真的应该将用户导航到thankyou.php页面时。
所以我的问题是如何删除这个警告?
$username = (isset($_POST['username'])) ? $_POST['username'] : '';
$newpassword = (isset($_POST['newpassword'])) ? $_POST['newpassword'] : '';
$loggedIn = false;
if (isset($_POST['submit'])) {
// don't use $mysqli->prepare here
$query = "UPDATE Teacher SET TeacherSalt = ?, TeacherPassword = SHA1(CONCAT(?,?)) WHERE TeacherUsername = ? LIMIT 1";
// prepare query
$stmt=$mysqli->prepare($query);
// You only need to call bind_param once
$stmt->bind_param("ssss",$salt,$newpassword,$salt,$username);
// execute query
//bind results
$stmt->bind_result($dbTeacherUsername,$dbTeacherPassword,$dbTeacherSalt);
$stmt->execute();
while($stmt->fetch()) {
if ($username == $dbTeacherUsername) {
$loggedIn = true;
}
}
/* close statement */
$stmt->close();
/* close connection */
$mysqli->close();
if ($loggedIn == true){
$_SESSION['username'] = $dbTeacherUsername;
header( 'Location: thankyou.php' ) ;
die();
}
}
if ($loggedIn == false && $_POST) {
echo "The Username you Entered is not Valid. Try Entering it Again.";
}
?>