我无法在更改密码页面中将密码更新为新密码,而且完全没有错误,所以找不到哪个是不正确的部分。我检查了 MySQL 表,它没有更新。有人可以帮忙查一下吗?谢谢。PHP代码 include "../setting/config.php"; session_start();$btnchange = filter_input(INPUT_POST, "btnchange");if(isset($btnchange)){ $username = filter_input(INPUT_POST, "username"); $password = filter_input(INPUT_POST, "password"); $query2 = "SELECT username from registered_accounts where username='$username'AND password='$password'"; $query_run=mysqli_query($conn, $query2); $level = mysqli_fetch_array($query_run); if(count(fetchAll($query2)) > 0){ //this is to catch unknown error. foreach(fetchAll($query2) as $row){ if ($row['username'] == $username && $row['password'] == $password) { $update_query2= "UPDATE registered_accounts set password='$password' where username='$username'"; $update_query_run=mysqli_query($conn, $update_query2); if ($update_query2) { echo "<script>alert('Password has been changed successfully.')</script>"; } else{ echo "<script>alert('Password has been failed to change.')</script>"; }}}}}?>身体<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input type="text" class="text" name="username" placeholder="Username" value="" required autofocus> <input type="password" placeholder="Password" name="password" value="" required autofocus> <div class="submit"><input type="submit" value="Submit" name="btnchange"></div></form>注册账户表
1 回答
莫回无
TA贡献1865条经验 获得超7个赞
您需要更新此新密码。并且这个新密码不是被查询用户的当前密码。因此选择查询无法检索任何结果。从 $query2 中删除 AND password='$password',如下所示:
$query2 = "SELECT username from registered_accounts where username='$username'";
并删除 if 语句,因为不需要再次检查。
if ($row['username'] == $username && $row['password'] == $password)
希望这会有所帮助,但我也建议您使用准备好的语句来防止 SQL 注入。
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消