我正在使用一個註冊系統的網站。在userCP中,您可以更改密碼。我爲它製作了這個腳本,但它不起作用。有人能幫助我嗎?當我更改密碼時,它不會給出錯誤,但它不會更新它。PHP更新密碼腳本不起作用
PHP代碼:
<?php
if (isset($_POST['updatePassBtn']))
{
$cpassword = $_POST['cpassword'];
$npassword = $_POST['npassword'];
$rpassword = $_POST['rpassword'];
if (!empty($cpassword) && !empty($npassword) && !empty($rpassword))
{
if ($npassword == $rpassword)
{
if (mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `username` = '".$_SESSION['username']."' AND `password` = '".SHA1($cpassword)."'")))
{
mysql_query("UPDATE `users` SET `password` = '".SHA1($npassword)."' WHERE `username` = '".$_SESSION['username']."' AND `ID` = '".$_SESSION['id']."'");
echo '<div class="nNote nSuccess hideit"><p><strong style="color:green;">SUCCESS: </strong>Password Has Been Updated</p></div>';
}
else
{
echo '<div class="nNote nFailure hideit"><p><strong style="color:red;">FAILURE: </strong>Current Password is incorrect.</p></div>';
}
}
else
{
echo '<div class="nNote nFailure hideit"><p><strong style="color:red;">FAILURE: </strong>New Passwords Did Not Match.</p></div>';
}
}
else
{
echo '<div class="nNote nFailure hideit"><p><strong style="color:red;">FAILURE: </strong>Please fill in all fields</p></div>';
}
}
?>
我的形式:
<form action="" class="form" method="POST">
<fieldset>
<label></label>
<input name="cpassword" type="text" value="Current Password" onfocus="this.value = (this.value=='Current Password')? '' : this.value;" onblur="if(this.value == ''){this.value='Current Password';}"/>
</fieldset>
<fieldset>
<label></label>
<input name="npassword" type="text" value="New Password" onfocus="this.value = (this.value=='New Password')? '' : this.value;" onblur="if(this.value == ''){this.value='New Password';}"/>
</fieldset>
<fieldset>
<label></label>
<input name="rpassword" type="text" value="Repeat Password" onfocus="this.value = (this.value=='Repeat Password')? '' : this.value;" onblur="if(this.value == ''){this.value='Repeat Password';}"/>
<input type="submit" value="Update" name="updatePassBtn"/>
</fieldset>
</form>
也許是JavaScript標記?沒有看到任何PHP或SQL。啊,更新後好一點。 – ficuscr 2013-03-14 18:46:49
**它輸出的是什麼?**你有一個'echo'遍佈整個地方,所以它必須輸出* something *。 – 2013-03-14 18:47:44
它只是輸出,它是成功的,所以我猜問題是在SQL中。 – wouterdz 2013-03-14 18:48:56