Having a bit of trouble with this PHP MYSQLi script - Whenever I run the function, I always get a return value of 0, even though I have satisfied the conditions to return another value. It appears my code is failing to collect data from the table, however I can't work out why. Here's my code:
function updatePassword($username, $oldPass, $newPass, $newPassConf, $mysqli){
if($stmt = $mysqli->prepare("SELECT password FROM members WHERE email = ?")){
$username = 'user'; //Temp value just to test the statement
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($dbOldPass);
$stmt->fetch();
}
else{
return 0; // Failed to retrieve pw from DB
}
if($dbOldPass == $oldPass){
if($newPass == $newPassConf){
if($stmt = $mysqli->prepare('UPDATE members SET password=? WHERE username=?')){
$stmt->bind_param('ss', $newPass, $username);
$stmt->execute();
return 1; // Success
}
}else{
return 2; // Password and PW confirmation are wrong
}
}
}
Thanks in advance for any help you may be able to give!