我试图创建一个忘记的密码脚本,但是我被捕了一点。
的问题是,$query = sprintf("UPDATE
用户SET
密码= '%s' WHERE
电子邮件= '$forgotpassword'", mysql_real_escape_string($newpassword));
并不在现场“密码”更新数据。
'忘记'值正根据需要进行更新。再次,我知道脚本连接到数据库,因为忘记的字段根据需要更新为'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是贬值,但它就是这个项目必须使用。刚刚和我一起去那个。
干杯
如果你被这个陈旧的界面卡住,使用'%s'来做你的转义并不是一个坏主意,但你应该一直使用它来清楚你正确地转义事物。 – tadman