0

I am writing a login form with PHP and Mysql.

I did everything its just the forgot password that is not working.

It sends me email confirmation but it does not update the password in the database.

First is the forgot page, then sends an email and redirect me to the confirm_pass.html page where is the form for the two passwords and on this page executes the confirm_pass.php where is doing everything, except updating the password in the database.

Please help.

 <?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 

// Make sure the two passwords match
if ( $_POST['newpassword'] == $_POST['confirmpass'] ) { 

    $new_password = password_hash($_POST['newpassword'], PASSWORD_BCRYPT);

    $email = $mysqli->escape_string($_POST['email']);
    $confirm_code  = md5(rand().$password);

    $result = "UPDATE `mv_db`.`users` SET `password`='$new_password', `confirm`='$confirm_code' WHERE `email`='$email'";

    if ( $mysqli->query($result) ) {
        header("location: login.html");    

    }

}
else {
    $_SESSION['message'] = " The two passwords you entered don't match, try again!";
    header("location: error.php");    
}

}
?>
user2342558
  • 5,567
  • 5
  • 33
  • 54
Nadia
  • 11
  • 4

1 Answers1

2

Your $_POST['email'] is not defined, because there is no "email" field in your HTML form.

So nothing is updated in database, because there is no matching record.

Syscall
  • 19,327
  • 10
  • 37
  • 52