Mysql Update无法正常工作,没有mysql错误

时间:2014-08-08 12:50:53

标签: php mysql

我确信我缺少一些简单的东西,但是这个更新查询无效。它正在返回“我们无法重置您的密码...”#39;错误,但没有显示mysql_error()。

    $usr = mysql_real_escape_string($_POST['username']);
    $email = mysql_real_escape_string($_POST['email']);

    $fpquery = "SELECT id, usr, email, rand FROM membertable WHERE usr = '$usr' AND email = '$email'";

    $fpresult = mysql_query($fpquery,$link);

    if(mysql_num_rows($fpresult) < 1) {


        $_SESSION['msg']['forgotpassword-err']= 'This username or email does not exist in our records. Make sure your capitalization is correct and please try again.';

        echo header("Location: ../forgotpassword.php");

    }

elseif(mysql_num_rows($fpresult) == 1) {

    $rand = $fpresult['rand'];

    $pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
    $insertpassword = hash("sha256",$pass.$rand);
    $fpid = $fpresult['id'];
    $fpusr = $fpresult['usr'];
    $fpemail = $fpresult['email'];

    $updatequery = "UPDATE membertable SET
                pass='$insertpassword',
                yn='2'
                WHERE id='$fpid' AND usr='$fpusr' AND email='$fpemail'";
    $updateresult = mysql_query($updatequery, $link);

    if(mysql_affected_rows($updateresult) == 1)
    {

        $_SESSION['msg']['forgotpassword-err']='You will receive an email with your temporary password. Please return to the home page and log in with this password to reset your password permanently';

        echo header("Location: ../forgotpassword.php");

    }

    else {

        $_SESSION['msg']['forgotpassword-err']='We were unable to reset your password. Please contact customer service at 888-888-8888 and mention the following error: ' . mysql_error();

        echo header("Location: ../forgotpassword.php");
    }
}

3 个答案:

答案 0 :(得分:0)

你不应该使用mysql_fetch_array()在某个时候获取$ fpquery的结果吗?

答案 1 :(得分:0)

如果您需要一行,首先始终使用限制1。

$fpquery = "SELECT id, usr, email, rand FROM membertable WHERE usr = '$usr' AND email = '$email' LIMIT 1";

您需要获取结果:
试试这个:

$result = mysql_query($fpquery,$link);
$fpresult = mysql_fetch_array($result);

答案 2 :(得分:0)

更新可能会影响零行或多行 - 这些情况都不会产生错误,但会导致“我们无法重置您的密码”。&#39;消息。