我試圖創建一個忘記的密碼腳本,但是我被捕了一點。
的問題是,$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