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);      
} 

一些更简单的事情是将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); 
    }
}

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

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

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