I need to be able to allow a user to reset their password via entering their email , which will then update the database, and send an email to the user with the updated password. they will also be redirected to a page that will allow them to update the password to something else, but I have been unable to get the database to update the password? Please help!
This is my code
<?php
$pwd_rand = rand();
$pwd_reset = $pwd_rand;
$email_password = $pwd_reset;
$new_password = sha1($email_password);
if (isset($_POST['useremail'])){
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->setFrom('test@phpserver.com', 'A Smith');
$to = $_POST['useremail'];
$mail->addAddress($to, 'Somebody');
$mail->Subject = 'PHPMailer mail() test';
$mail->msgHTML($new_password." This is your new password." );
if (isset($_POST['submit'])){
$db_server = "127.0.0.1";
$db_usr = "";
$db_pwd = "";
$db = $db_usr;
$conn = mysqli_connect($db_server, $db_usr, $db_pwd, $db);
$q = "SELECT * FROM login WHERE email = '$to'";
$row = mysqli_fetch_assoc($queryget);
$r = mysqli_query($conn, $q);
$querychange = mysqli_query($conn, "UPDATE login SET password='$newpassword' WHERE email='$to'");
mysqli_close($conn);
}
if (!empty($_POST[$useremail])){
mail($to, "From: ");
} else {
echo "<div class=\"msg\">Please supply your email address.</div>";
}
} else {
echo "<div class=\"msg\">Please supply your email address.</div>";
}
}
{
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
echo "<div class=\"msg\">Password has been reset, check your email.</div>";
echo "<script>setTimeout(\"location.href = 'changepassword.php';\",1500);</script>";
}}
?>
This is what i am working with at this moment^ my code will send the email with the new password, and redirects to the update password page, but it fails to update the database with the new password?