prepare("SELECT password FROM user WHERE id_user=:id_user"); $stmt_file->bindValue(':id_user', $_SESSION['id_user']); $stmt_file->execute(); $rows = $stmt_file->fetchAll(PDO::FETCH_ASSOC); //check if user missing if(!count($rows)) { http_response_code(404); echo 'user not found'; return; } //validate password entered if(!password_verify($password_old, $rows[0]['password'])) { http_response_code(403); echo 'invalid old password'; return; } $stmt_file = $dbh->prepare("UPDATE user SET password = :password WHERE id_user = :id_user"); $stmt_file->bindValue(':id_user', $_SESSION['id_user']); $stmt_file->bindValue(':password', password_hash($password_new)); $stmt_file->execute(); $rows = $stmt_file->fetchAll(PDO::FETCH_ASSOC); echo 'OK'; ?>