我正在尝试构建用户密码页面,通过检查“old_password”salt并匹配它来更新密码,以便将其更改为新密码。我只是不知道如何使用MySQLi,MySQL是最简单的,但这个对我来说只是复杂和混乱。我还在研究这些,希望能够到达某个地方。
请告诉我我目前在下面得到的错误,如果你有时间,可以帮我解决下面的问题吗,那将非常有帮助。我已经坚持了4天以上,无法做任何事情来修复它,还检查了网络,仍然没有帮助。
<?php
// connect to database
$database = mysqli_connect("localhost", "root", "", "mydbname");
if(isset($_POST['update_password']))
{
// check if old password salt matches
$rs_pwd = mysqli_query($database, "SELECT pwd FROM users WHERE id='$_SESSION[user_id]'");
list($old) = mysqli_fetch_row($rs_pwd);
$old_salt = substr($old,0,9);
// check for old password in md5 format
if($old === PwdHash($_POST['pwd_old'],$old_salt))
{
$newsha1 = PwdHash($_POST['pwd_new']);
mysqli_query($database, "UPDATE users SET pwd='$newsha1' WHERE id='$_SESSION[user_id]'");
// password updated
header("Location: /password.php?action=password_updated);
die();
}
else
{
// password does not match, so return an error here
header("Location: /password.php?action=password_does_not_match");
die();
}
}?>
这是我的HTML表单:
<form action="" method="POST">
<label for="pwd_old">Old Password:</label><br />
<input type="password" name="pwd_old">
<br /><br />
<label for="pwd_new">New Password:</label><br />
<input type="password" name="pwd_new">
<br /><br />
<input type="submit" name="update_password" value="Update Password">
</form>
编辑:我也收到此错误:
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\password.php on line **xx**