我的登录系统工作正常,但作为一个小项目,我无法让密码更新工作。
有人可以尝试阅读代码,看看他们是否能看到我造成的错误?通过长时间的观察,我可能会感到很遗憾。
那么我得到的错误是什么?当我输入我在$OLDPASSWORD
上登录时更新的密码时,它会一直给我$OLDPASSWORD
结果,即我的旧密码与数据库中的密码不匹配,即使它已经存在。< / p>
<?php
session_start();
include("setup.php");
include("top.php");
$action = (isset($_GET['action'])) ? $_GET['action'] : '';
$names = mysql_query('SELECT * FROM userdb WHERE username = "'. mysql_real_escape_string($_SESSION['username']) . '"') or trigger_error(mysql_error());
$row = mysql_fetch_array($names);
if($action == "") {
echo "<form action=http://www.sentuamessage.com/changepassword.php?action=password method=POST>
<div align = center>
<table border=0 width=34% cellspacing=0 cellpadding=0>
<tr>
<td width=162>Old Password</td>
<td><input type=password name='oldpassword'></td>
</tr>
<tr>
<td width=162 height=5></td>
<td></td>
</tr>
<tr>
<td width=162>New Password</td>
<td><input type=password name='newpassword'></td>
</tr>
<tr>
<td width=162 height=5></td>
<td></td>
</tr>
<tr>
<td width=162>Confirm New Password</td>
<td><input type=password name='repeatnewpassword'></td>
</tr>
<tr>
<td width=162 height=5></td>
<td></td>
</tr>
<tr>
<td width=162> </td>
<td>
<p align=right><input type=submit name =submit value=submit></td>
</tr>
</table>
</div>
</form>";
include("bottom.php");
exit;
}
if($action == "password") {
if (!isset($_SESSION['username'])) {
echo "<p align=center>You have to be logged in to change your password. Please <a href=http://www.sentuamessage.com/login.php>login</a></p>";
}
else
{
if (isset($_POST['submit']))
{
$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);
$queryget = mysql_query("SELECT password FROM userdb WHERE username='$row[name]'") or trigger_error(mysql_error());
$rownew = mysql_fetch_assoc($queryget);
$oldpassworddb = $rownew[password];
if ($oldpassword==$oldpassworddb)
{
if ($newpassword==$repeatnewpassword)
{
$querychange = mysql_query("UPDATE userdb SET password='$newpassword' WHERE username='$row[name]'") or trigger_error(mysql_error());
echo "<p align=center>Your password has been changed. <a href=http://www.sentuamessage.com/login.php> Re Login</a></p>";
session_destroy();
}
else
echo "<p align=center>Sorry your New Password does not match. Please<a href=http://www.sentuamessage.com/changepassword.php> Try Again</a></p></p>";
}else
echo "<p align=center>Sorry your Old Password does not match. Please<a href=http://www.sentuamessage.com/changepassword.php> Try Again</a></p></p>";
}
}
include("bottom.php");
exit;
}
?>
答案 0 :(得分:3)
检查此行..出错了?:
$oldpassworddb = $rownew[password];
应该是吗?:
$oldpassworddb = $rownew['password'];