I am trying to create a forget password webpage using PHP and JS. Although when I try add an email address, and click "reset password" nothing happens, and there are no errors in the console. What I want is for the text to appear so the user knows if their password has been reset. But nothing happens and I am unsure what the problem is. If anyone has any ideas can you please let me know. Thanks
<?php
use PHPMailer\PHPMailer\PHPMailer;
require_once "functions.php";
if (isset($_POST['email'])) {
require_once('config1.php');
$email = $conn->real_escape_string($_POST['email']);
$sql = "SELECT user_id FROM zz_login WHERE email='$email'";
$result = mysqli_query($conn, $sql, MYSQLI_USE_RESULT);
if (mysqli_num_rows($result) > 0) {
$token = generateNewString();
$sql = "UPDATE zz_login SET token='$token',
tokenExpire=DATE_ADD(NOW(), INTERVAL 5 MINUTE)
WHERE email='$email' ";
$result = mysqli_query($conn, $sql, MYSQLI_USE_RESULT);
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail->addAddress($email);
$mail->setFrom("", "");
$mail->Subject = "Reset Password";
$mail->isHTML(true);
$mail->Body = "
Hi,<br><br>
In order to reset your password, please click on the link below:<br>
<a href='
URL/resetPassword.php?email=$email&token=$token
'>URL/resetPassword.php?email=$email&token=$token</a><br><br>
Kind Regards,<br>
Trip Guider
";
if ($mail->send())
exit(json_encode(array("status" => 1, "msg" => 'Please Check Your Email Inbox!')));
else
exit(json_encode(array("status" => 0, "msg" => 'Something Wrong Just Happened! Please try again!')));
} else
exit(json_encode(array("status" => 0, "msg" => 'Please Check Your Inputs!')));
}
?>
Javascript
alert(response);
response= $.parseJSON(response);
if (!response.status)
var email = $("#email");
$(document).ready(function () {
$('.btn-primary').on('click', function () {
if (email.val() != "") {
email.css('border', '1px solid green');
$.ajax({
url: 'forgotPassword.php',
method: 'POST',
dataType: 'json',
data: {
email: email.val()
}, success: function (response) {
if (!response.success)
$("#response").html(response.msg).css('color', "red");
else
$("#response").html(response.msg).css('color', "green");
}
});
} else
email.css('border', '1px solid red');
});
});
e 13 is if (mysqli_num_rows($result) > 0) { – – CD6554 Feb 25 '18 at 12:08