I do not understand why $colpassword
does not return a value?: by application in Android step study the id , the old password and the new
$userId = $_POST["userId"];
$oldPassword = $_POST["oldPassword"];
$newPassword= $_POST["newPassword"];
$statement = mysqli_prepare($con, "SELECT password FROM users WHERE`E id = ?");
mysqli_stmt_bind_param($statement, 'i', $userId);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $colPassword);
mysqli_stmt_close($statement);
error_log($colPassword . "-" . $oldPassword, 3 , "/var/www/html/inf-5mgruppo1/messaggi.log");
$response = array();
$response["success"] = false;
if (password_verify($oldPassword, $colPassword)){
$response["success"] = true;
//update on database
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
$statement_up = mysqli_prepare($con, "UPDATE users SET password = ? WHERE id = ?");
mysqli_stmt_bind_param($statement_up, "si", $hashedPassword, $userId);
mysqli_stmt_execute($statement_up);
mysqli_stmt_close($statement_up);
}
echo json_encode($response);
You still have to fetch the data:
mysqli_stmt_bind_result($statement, $colPassword);
mysqli_stmt_fetch($statement); // fetch!
mysqli_stmt_close($statement);