token在mysql数据库中没有更新

zpgglvta  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(393)
<?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` 在my db中更新,但令牌不仅更新,而且不在db中创建。这是忘记密码系统通过令牌和发送它通过邮件,但我只是做这个系统的开始。
请帮助我,因为我是一个初学者,不能解决这个问题很长一段时间。
mrphzbgm

mrphzbgm1#

检查令牌字段类型(如果是整数或varchar)。如果是整数,则转换为varchar(255)。

相关问题