我正在一个带有注册系统的网站上工作。在 userCP 中,您可以更改您的密码。我为它制作了这个脚本,但它不起作用。有人可以帮助我吗?当我更改密码时,它没有给出错误,但它只是没有更新它。
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>