$query = sprintf未更新MySQL数据库


$query = sprintf not updating MySQL database

我试图创建一个忘记密码的脚本,但是我有点被赶上了。

问题是,$query = sprintf("UPDATE用户SET密码= '%s' WHERE电子邮件= '$forgotpassword'", mysql_real_escape_string($newpassword));没有更新字段'password'中的数据。

'forgot'值正在根据需要更新。再一次,我知道脚本正在连接到数据库,因为遗忘字段根据需要更新为'1'。

下面是代码:
//Generate a RANDOM MD5 Hash for a password
$random_password=md5(uniqid(rand()));
//Take the first 8 digits and use them as the password we intend to email the user
$emailpassword=substr($random_password, 0, 8);
//Encrypt MD5 format for the database
$newpassword = md5($emailpassword);
    // Make a safe query
    $query = sprintf("UPDATE `users` SET `password` = '%s' 
                      WHERE `email` = '$forgotpassword'",
                mysql_real_escape_string($newpassword));
    $query = sprintf("UPDATE `users` SET `forgot` = '1' 
                      WHERE `email` = '$forgotpassword'");
                mysql_query($query)or die('Could not update members: ' . mysql_error());

我知道这个版本的MYSQL是贬值的,但它是这个项目必须使用的。这一点你得同意我的看法。

欢呼

第一次更新时没有调用mysql_query($query),只有第二次。

// Make a safe query
$query = sprintf("UPDATE `users` SET `password` = '%s' 
                  WHERE `email` = '$forgotpassword'",
            mysql_real_escape_string($newpassword));
// NEED TO CALL mysql_query($query); HERE
$query = sprintf("UPDATE `users` SET `forgot` = '1' 
                  WHERE `email` = '$forgotpassword'");
mysql_query($query)or die('Could not update members: ' . mysql_error());

您正在编写两个查询,但只执行一个。

可能密码没有更新,因为WHERE子句不匹配任何行…

您确定在WHERE email = '$forgotpassword'中设置了邮箱吗?