I am trying to create a change password page with this php script. I want to be able to tell the user whether or not they have put in the correct username and password so that it may be changed. When I check the rows, regardless if it returns rows or not, I always get this error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
This is my code:
<?php
$uname = mysqli_real_escape_string($conn, $_POST['uname']);
$currentpw = mysqli_real_escape_string($conn, $_POST['currentpw']);
$newpw1 = mysqli_real_escape_string($conn, $_POST['newpw1']);
$newpw2 = mysqli_real_escape_string($conn, $_POST['newpw2']);
$sql = "UPDATE USERS
SET password = '$newpw1'
WHERE username = '$uname' and password = '$currentpw'";
$result = mysqli_query($conn, $sql);
$row = mysqli_num_rows($result);
if($row > 0 && $newpw1 == $newpw2){
mysqli_query($conn, $sql) or die(mysqli_error($conn, $sql));
}
else if($newpw1 != $newpw2){
echo "Passwords do not match";
}
else {
echo "Username or Password is incorrect";
}
}
?>
note: i do make a connection before hand just doesn't seem necessary to have it on here. Also if I do enter the right information it will change the password as needed but still have the error message