Codeigniter 更新记录 - 无法在数据库中更新

Codeigniter Update Record - Unable to update in database

我正在尝试更新 CI 项目中的记录。我可以稍后处理表单验证。现在我正在尝试解决无法更新数据库中记录的问题。

我正在为所有页面使用模板并放置所有内容。任何帮助,将不胜感激。

更新记录的模型

 public function up_ct_acct($id, $sus) 
 {  
 $this->db->where('user_id',$id);  
  $this->db->update('users',$sus); 
 }  

表单视图和操作的控制器

//for page view
public function update_profile($id, $datum)
{ 
   //the username is on the url.
   $id = $this->uri->segment(3);    
   $datum['user_profile'] = $this->user_model->get_da_profile($id);
   //using a template for all pages
   $content['main_content'] = $this->load->view('users/update_profile',$datum); 
   $this->load->view('main',$content); 
} 
//action to update 
public function up_sup_acct() 
{ 
      $first_name = $this->input->post('first_name'); 
      $last_name = $this->input->post('last_name');  
      $phone = $this->input->post('phone'); 
      $mobile = $this->input->post('mobile'); 
      $city = $this->input->post('city'); 
      $country = $this->input->post('country'); 
      $description = $this->input->post('description'); 
      $date_edited = $this->input->post('today');     

      $sus = array( 
         'first_name' => $first_name, 
         'last_name' => $last_name, 
         'phone' => $phone, 
         'mobile' => $mobile, 
         'city' => $city,
         'country' => $country, 
         'description' => $description, 
         'date_edited' => $date_edited
         );

      $this->user_model->up_ct_acct($id,$sus);      
} 

在您调用的控制器中的 up_sup_acct() 操作中

$this->user_model->up_ct_acct($id,$sus); 

但是你的 $id 变量没有设置。

一些更简单的事情是将 post 数据放入模型和 id 中,像这样 $this->db->where('user_id',$this->uri->segment(3));

<?php

class Users extends CI_Controller {

    public function update_profile($id, $datum) { 
        $id = $this->uri->segment(3);    
        $datum['user_profile'] = $this->user_model->get_da_profile($id);
        $content['main_content'] = $this->load->view('users/update_profile',$datum); 
        $this->load->view('main',$content); 
    } 

    public function up_sup_acct() { 
        $this->load->model('user_model');
        $this->user_model->up_ct_acct();      
    } 

}

?>

型号

<?php

class User_model extends CI_Model {

    public function up_ct_acct() {
        $data = array(
            'first_name' => $this->input->post('first_name'),
            'last_name' => $this->input->post('last_name'),
            'phone' => $this->input->post('phone'),
            'mobile' => $this->input->post('mobile'),
            'city' => $this->input->post('city'),
            'country' => $this->input->post('country'),
            'description' => $this->input->post('description'),
            'date_edited' => $this->input->post('today') 
        );

        $this->db->where('user_id',$this->uri->segment(3));  
        $this->db->update('users',$data); 
    }
}