我确定我在这里某处犯了一个非常愚蠢的错误 - 所以我正在创建这个更改密码表单并使用非常粗暴的OOP尝试 - 到目前为止,我没有任何'更改密码'代码因为我试图先解决错误。
所以,我的问题是这样的 - 当我提交表单时,我收到错误“请填写每个字段!”尽管事实上所有三个领域都已完成。再一次,我确信我犯了一个非常愚蠢的错误,但我可以帮助你! Ty提前! :)
代码位于表单页面顶部
if (empty($_POST) === false) {
$password = trim($_POST['password']);
$newpassword = trim($_POST['newpassword']);
$confpassword = trim($_POST['confnewpassword']);
$id = $_SESSION['id'];
if (empty($password) === true || empty($newpassword) === true || empty($confnewpassword) === true) {
$errors[] = 'Please fill out each field!';
} else if ($users->current_password($password) === false) {
$errors[] = 'Current password is incorrect!';
} else if ($newpassword != $confpassword) {
$errors[] = 'New password and Confirm password do not match!';
} else if ($password == $newpassword){
$errors[] = 'You cannot change your password to your existing password';
}else {
$errors[] = 'Password Changed!';
}
}
我的current_password功能
public function current_password($password) {
$id = $_SESSION['id'];
$query = $this->db->prepare("SELECT `password` FROM `users` WHERE `ID` = ?");
$query->bindValue(1, $id);
$enteredpassword == $password;
try{
$query->execute();
$storedpass = $query->fetchColumn();
if ($storedpass === sha1($enteredpassword)) {
return true;
} else {
return false;
}
} catch (PDOException $e){
die($e->getMessage());
}
}
我的HTML表单
<form class="form-horizontal" role="form" method="POST">
<div class="form-group">
<label class="col-sm-4 control-label">EIN / Username</label>
<div class="col-sm-8">
<input class="form-control" id="disabledInput" type="text" placeholder="<?php echo $ein; ?>" disabled>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-4 control-label">Enter Existing Password</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="password" placeholder="Enter Existing Password">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-4 control-label">Enter New Password</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="newpassword" placeholder="Enter New Password">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-4 control-label">Confirm New Password</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="confnewpassword" placeholder="Confirm New Password">
</div>
</div>
<button type="submit" class="btn btn-primary btn-block">Change Password</button>
</form>
答案 0 :(得分:1)
您的confime密码varibale名称是$ confpassword
$confpassword = trim($_POST['confnewpassword']);
您在
中使用$ conf密码if (empty($password) === true || empty($newpassword) === true || empty($confnewpassword) === true)