我试图更改已登录用户的密码,但是当我运行代码时,它总是更改表的顶行,并且登录用户位于中间的某个位置。
用户代码
验证码
<?php
session_start();
include ('dbc.php');
if (!isset($_SESSION['user'])) {
header("Location: login.php");
}
$id = mysql_real_escape_string($_SESSION['id']);
$todo=$_POST['todo'];
$oldpwd=$_POST['oldpwd'];
$newpwd=$_POST['newpwd'];
if ($_POST['Submit']=='Change') {
$result = mysql_query("select * from users where id='$id'")
or die("asdasdsd".mysql_error());
while($row=mysql_fetch_array($result)) {
if ($_POST["oldpwd"] == $row["user_pwd"]) {
mysql_query("UPDATE users set user_pwd='$newpwd' WHERE id='$id'");
header("Location: userpanel.php?msg=Password updated...");
} else {
header("Location: userpanel.php?msg=ERROR: Password does not match...");
}
}
}
?>