Search code examples
phpmysqliprepared-statementzerorows-affected

mysqli nuw_rows always returns 0


I've gone through forums and posts, but i just can't seem to figure out what i'm doing wrong here.

i tried $mysqli->num_rows first to get the affected rows, but appearantly that only works for SELECT statements. Unfortunately, ..->affected_rows also seems to return 0 every time. What is the problem?

$key = $email . $password . $mysqli->mysqli_salt;
$update_password = "UPDATE `users` SET `password`=SHA1(?) WHERE `surname`=? AND `lastname`=? AND `email`=?";
$stmt_update = $mysqli->prepare($update_password);
$stmt_update->bind_param("ssss", $key, $surname, $lastname, $email);
$stmt_update->execute();
$rows = $stmt_update->affected_rows; //i've also tried '$mysqli->affected_rows;
if ($rows != 1) {
   echo 'error';
}
$stmt_update->close();

thanks!


Solution

  • Try setting the password to something else, not the same value over and over again. If the password does not change, the row does not count as updated.