Advertisements
I would like to change the login password for a user using the following script:
<?php
#Salir si alguno de los datos no está presente
if(!isset($_POST["email"])) exit();
#Si todo va bien, se ejecuta esta parte del código...
include_once "conectar_pdo.php";
$password = $_POST['password'];
$email = $_POST['email'];
/*
Al incluir el archivo "conectar_pdo.php", todas sus variables están
a nuestra disposición. Por lo que podemos acceder a ellas tal como si hubiéramos
copiado y pegado el código
*/
//convertimos la pass a pass real
$encrypted_password = password_hash($password, PASSWORD_DEFAULT);
$sentencia = $base_de_datos->prepare("UPDATE tb_administradores SET
encrypted_password = ? WHERE email = ?");
$resultado = $sentencia->execute([ $encrypted_password, $email]); # Pasar en Pasar en el mismo orden de los ?
#execute regresa un booleano. True en caso de que todo vaya bien, falso en caso contrario.
#Con eso podemos evaluar
if($resultado === TRUE) echo json_encode(array("success"=>true));
else echo json_encode(array("success"=>false));
Here you have the table fields
My issue is that I am getting as output from the script the response
{"success":true}
but the field encrypted_password is not updated
>Solution :
Since you have the condition WHERE email = ?
and the row is not updated, it would mean that the row does not exist.
The result would be {success:true}
because the query did succeed, there were no errors.
The value in $email
does not match what is stored. Debug it and display the value,