PHP从MYSQL数据库返回不正确的记录

时间:2016-12-15 06:56:32

标签: javascript php jquery mysql sql

拥有以下代码..我已经为我的网站设置了密码重置系统,它突然崩溃了。我正在将表单从标准HTML / PHP发送数据方法改为使用AJAX .post()方法,但不要认为这与我看到的结果有任何关系。

问题:当$ timeSQL查询运行时,它返回0 num_rows(),但是当我在phpmyadmin中运行它时,我得到了预期的结果。我没有在我的SQL语句中使用count(*),因为我看到很多这些答案都在引用,所以我不确定是什么问题..

每次尝试我总是会触发此代码:

echo "<script> 
       alert('It has been longer than 1 hour since you last requested to reset your password and your code has expired.  Please request to reset it again on the login page by clicking Forgot Password link at the bottom of the login page.');
       window.location='login.php';
     </script>";

以下是具有相同代码的pastebin:http://pastebin.com/S5Yi9MAQ

感谢所有帮助

<?php

include('config.php');

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

$token = $_GET["token"];

if (isset($_POST['rpTempCode'])){
    //Check to see if more than 10 mins has elapsed since password reset request
    $timeSQL = "SELECT codeExpireDate, sysdate(), tempCode FROM users WHERE token = '".$token."' AND codeExpireDate > sysdate()";
    $timeResult = mysqli_query($db,$timeSQL);


    $count = mysqli_num_rows($timeResult);
    echo "<script>alert('count: ".$count."');</script>";


    if (mysqli_num_rows($timeResult) > 0){
        $timeRow = $timeResult->fetch_assoc();

        $tempCodeFromDB = $timeRow["tempCode"];

        $newPassword = mysqli_escape_string($db, $_POST["rpNewPassword"]);
        $tempCode = mysqli_escape_string($db, $_POST["rpTempCode"]);

        if ($tempCode == $tempCodeFromDB){
            $sql = "UPDATE users SET password = '".$newPassword."', locked = 0 WHERE token = '".$token."'";
            $result = mysqli_query($db,$sql);
            if ($result == FALSE){
                //add error handling here..
                echo "Error updating new password in DB..";
            } else {
                //good
                echo "<script> alert('Password updated! You can now login.'); window.location='login.php'; </script>";
            }
        } else {
            echo "<script> alert('Incorrect code entered, please try again.'); </script>";
        }
    } else {
        echo "<script> alert('It has been longer than 1 hour since you last      requested to reset your password and your code has expired.  Please request to reset it again on the login page by clicking Forgot Password link at the bottom of the login page.');
                       window.location='login.php';
            </script>";
    }
}

更新 到目前为止,我已经确定在尝试使用PHP的$ result-&gt; num_rows&gt;时存在问题。 0使用jQuery .post()方法。每次返回0个记录返回计数。试图返回所有数据然后在接收JS / jQuery端进行计数并使用类似:

var rowCount = $('#countMe').length;

计算所有回来的div,认为它会起作用,但也失败了..

0 个答案:

没有答案