Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Field not updated after executing UPDATE in MySQL table

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

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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,

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading