<?php
if (isset($_POST['email'])) {
include 'dbconn.php';
$email = $conn->real_escape_string($_POST['email']);
$sql = $conn->query("SELECT id from users WHERE userEmail='$email'");
if (!empty($sql) && $sql->num_rows > 0) {
$token = "poiuytrewqlkjhgfdsamnbvcxz1234567890";
$token = str_shuffle($token);
$token = substr($token, 0, 10);
$conn->query("UPDATE users SET token = '$token',
tokenExpire = DATE_ADD(NOW(), INTERVAL 5 MINUTE)
WHERE userEmail='$email'");
exit(json_encode(array("status" => 1, "msg" => "Please check your Email inbox!")));
}
else{
exit(json_encode(array("status" => 0, "msg" => "Please check your inputs!")));
}
}?>
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-6" align="center">
<img src="images/logo.jpg" width="300" height="300">
<input type="email" name="email" class="form-control" id="email" placeholder="Email">
<input type="submit" name="" class="btn btn-primary" value="Reset password">
<br>
<p id="response"></p>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript">
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');
}
})
});
</script>
tokenExpire
is updated in my db, but token is not only updated, also is not created in db. This is forgot password system through token and sending it to via mail, but I am doing only the beginning of this system.
Please help me cuz I am a beginner and cannot solve this problem for a long time.
Check the token field type, if its integer or Varchar. If its integer then convert to Varchar(255).