我正在创建一个名为changepassword.php的php文件,该文件的唯一目的是允许用户更改其密码。然而,当他们通过表单更改密码时,框字段清除,我收到回声警告回显"密码框被留空!"。这似乎不想更新用户的密码,我不知道该怎么做。我是这种语言的新手,所以不要期待太多。我非常感谢一些有助于我更好地编写php的建设性意见。
<?php
session_start();
#error_reporting(E_ALL); ini_set('display_errors', 1);
require_once('connect.php');
require_once "lib.php";
require_once "utils.php";
if(isset($_POST['submit']) && $_SESSION['active']===true)
{
if(!empty($_POST['OldPassword'])&&
!empty($_POST['NewPassword'])&&
!empty($_POST['NewPassword1']))
{
$OldPassword = mysqli_real_escape_string($link,htmlentities($_POST['OldPassword']));
$NewPassword = mysqli_real_escape_string($link,htmlentities($_POST['NewPassword']));
$NewPassword1 = mysqli_real_escape_string($link,htmlentities($_POST['NewPassword1']));
$EmailAdress = $_SESSION['EmailAdress'];
$sql = "SELECT * FROM users WHERE EmailAddress='$EmailAddress'";
if($result = mysqli_query($link, $sql))
{
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$temp1=$row['Password'];
if($row['Password'] != $OldPassword)
{
echo "<div id='change_error1'>* This Does Not Match Previous Password!<br></div>";
}
}
if($NewPassword != $NewPassword1)
{
echo "<div id='change_error2'>* You Passwords DO NOT Match!</div>";
}
if($temp1 == $OldPassword && $NewPassword == $NewPassword1)
{
$sql = "UPDATE users SET Password='$NewPassword' WHERE EmailAddress='$EmailAddress'";
if($result = mysqli_query($link, $sql))
{
header("Location: profile.php");
echo "<strong>YOURE PASSWORD HAS BEEN UPDATED!</strong>";
}
}
}
}
else
{
echo "<div id='change_error3'>A Password Box was Left Empty!</div>";
}
}
?>
<html>
<head>
<title>Change Password</title>
</head>
<br></br>
<br></br>
<body class="body">
<div id="wrapper">
<div id="header">
<br>
<h1> PHP Learning Course </h1>
<br>
<?php require_once "left.php" ?>
</div>
<div id="change">
<div id="change_name">
<h3> Change Password</h3>
</div>
<p>
<div id='change_form'>
<form action='changepass.php' method='POST'>
Old Password:<br> <input name='OldPassword' type='password'/></br>
<br>
New Password:<br> <input name='NewPassword' type='password'/></br>
<br>
Confirm Password:<br> <input name='newpass1' type='password'/></br>
<br>
<input name='submit' type='submit' value='Change Password' />
</form>
</p>
</div>
</div>
<!-- end main div -->
</div>
<!-- end wrapper div -->
</body>
</html>
答案 0 :(得分:0)
!empty($_POST['NewPassword1']))
索引应为newpass1
即。 !empty($_POST['newpass1']))
因为在表单中,你已经放了
Confirm Password:<br> <input name='newpass1' type='password'/></br>
坚持一个惯例以避免这些错误。