我试图允许用户在登录后在个人资料编辑页面中更新密码。我有两个问题。首先,我收到一条警告,上面写着
警告:PDOStatement::execute()最多需要1个参数,第115行需要2个参数
这是
$stmt->execute(":password",$changed_password);
我尝试了不同的语法,但这里出现了错误。
第二个问题是密码实际上没有更新。下面是代码(包括如何为当前用户创建到db的连接)
<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();
$msg = '';
if(!$user_home->is_logged_in())
{
$user_home->redirect('signin.php');
}
$stmt = $user_home->runQuery("SELECT * FROM user WHERE id=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// print_r($row['learner_type']);
?>
以上代码位于我的文件的开头。
提交表单后会触发以下代码。
<?php
if(isset($_POST['reset_password']))
{
$old_pass=$_POST['txtoldpassword'];
$new_pass=$_POST['txtnewpass1'];
$re_pass=$_POST['txtnewpass2'];
if($row['password']==md5($old_pass)){
if($new_pass==$re_pass){
$changed_password=md5($re_pass);
$email = $row['email'];
$query = $user_home->runQuery("UPDATE user SET password='$changed_password' WHERE email='$email'") or die("Could not change password at this time.");
$stmt->execute(":password",$changed_password);
?>
<div class='alert alert-success alert-dismissible'>
<button class='close' data-dismiss='alert'>×</button>
<strong>Password Updated Successfully</strong>
</div>
<?php
}
else{
?>
<div class='alert alert-danger'>
<button class='close' data-dismiss='alert'>×</button>
<strong>Your new passwords do not match</strong>
</div>
<?php
}
}
else
{
?>
<div class='alert alert-danger'>
<button class='close' data-dismiss='alert'>×</button>
<strong>Your old password is incorrect</strong>
</div>
<?php
}
}
?>
谢谢你的帮助。注意,我已经检查了$email=$行['email'];并返回当前登录的用户。