gpt4 book ai didi

php - 无法在 codeigniter 中更新我的数据库记录,没有出现错误

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:45 28 4
gpt4 key购买 nike

我是 php 的新手,没有出现任何错误,但显然无法更新数据库中的数据。

The controller

  public function update_user_view() { 
$this->load->helper('form');
$user_id = $this->uri->segment('3');
$query = $this->db->get_where("users",array("user_id"=>$user_id));
$data['records'] = $query->result();
$data['old_user_id'] = $user_id;
$this->load->view('user_edit',$data);
}

public function update_user(){
$this->load->model('user_model');

$data = array(
'user_id' => $this->input->post('user_id'),
'name' => $this->input->post('name'),
'nickname' => $this->input->post('nickname'),
'email' => $this->input->post('email'),
'hadd' => $this->input->post('hadd'),
'gender' => $this->input->post('gender'),
'cpnum' => $this->input->post('cpnum'),
'comment' => $this->input->post('comment')

);

$old_user_id = $this->input->post('old_user_id');
$this->user_model->update($data,$old_user_id);

$query = $this->db->get("users");
$data['records'] = $query->result();
$this->load->view('user_view',$data);
}

the model

<?php 
class User_model extends CI_Model {

function __construct() {
parent::__construct();
}

public function insert($data) {
if ($this->db->insert("users", $data)) {
return true;
}
}

public function delete($user_id) {
if ($this->db->delete("users", "user_id = ".$user_id)) {
return true;
}
}

public function update($data,$old_user_id) {
$this->db->set($data);
$this->db->where("user_id", $old_user_id);
$this->db->update("users", $data);
}
}
?>

最佳答案

就这样

$this->db->where("user_id", $old_user_id); 
$this->db->update("users",$data);

关于php - 无法在 codeigniter 中更新我的数据库记录,没有出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40827636/

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