PHP mysql, update record fail but no error.
$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;
}
I know why it don’t update, incorrect values in the WHERE
clause. If the values are correct it updates just fine. But no errors to be seen anywhere when it fails, with or without a successful update the $mysqli->query($sql)
are true
.
How to catch the error?
I'm new to this, and I should probably look into PDO or what it's called, but shouldn't mysqli give an error of some sort? This is on a XAMPP localhost.
You don't get an error, because there was no error, your search criteria just did not match any results. If you want to get the number of rows affected by the query, do just that, use affected_rows()
.
$updated = $mysqli->affected_rows();
if ( $updated == 0 ) {
echo "None were updated!";
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments