gpt4 book ai didi

php - 如何在codeigniter模型中使用session

转载 作者:行者123 更新时间:2023-11-29 21:16:24 25 4
gpt4 key购买 nike

我创建了一个密码更改代码,在 postman 中我应该使用userid给出旧密码和新密码,当我创建更改密码时,但无法更改密码,它在数据库中保持不变,并且我认为问题出在 session 上。有人可以看到我的代码中的错误吗?

Controller

  public function changepasswordcheckagain() {

$arr = array();
$arr['old_password'] = $this->input->post('old_password');
$arr['new_password'] = $this->input->post('new_password');
$this->load->model('User_model');
$result = $this->User_model->checkPasswordfor($arr);
echo json_encode($result);
if ($result) {

echo json_encode('success');exit;
} else {
echo json_encode($result);
echo json_encode('fail');exit;

}
}

型号

  public function checkPasswordfor($arr)
{
$user_id = $this->session->userdata('user_id');
$this->db->select('*');
$this->db->from('userdetails');
$this->db->where('user_id',$user_id);
//$this->db->where('user_password',$arr['old_password']);
$query=$this->db->get();
$result=$query->result();
if($result){
$layout['user_password'] = $arr['old_password'];
$layout_data['user_password'] = $arr['new_password'];

$this->db->where('user_id',$user_id);
$this->db->update('userdetails',$layout_data, $layout);
return true;
}else{
return false;
}
}

最佳答案

试试这个代码: Controller

  public function changepasswordcheckagain() {

$user_id = $this->session->userdata('user_id');

$arr = array();
$old_password = $this->input->post('old_password');
$new_password = $this->input->post('new_password');

$this->load->model('User_model');
$where = ['user_id' => $user_id];

//$data['password'] ---> column name
//$data['password' => $new_password] ---> new value of column
$data = [
'password' => $new_password
];

$result = $this->User_model->checkPasswordfor($where, $data);

echo json_encode($result);
if ($result == TRUE) {

echo json_encode('success');exit;
} else {
echo json_encode($result);
echo json_encode('fail');exit;

}
}

型号

   public function checkPasswordfor($arr)
{
$this->db->where($where);
if($this->db->update('table name',$data))
{
return TRUE;
}
else
return FALSE;
}

关于php - 如何在codeigniter模型中使用session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35910185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com