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

杰弗里·特鲁埃尔

我正在尝试更新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);      
} 
ED先生

更简单的方法是像这样将发布数据放入模型和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); 
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Codeigniter更新数据库记录列表

来自分类Dev

记录未在数据库中更新

来自分类Dev

更新Codeigniter中的特定数据库记录

来自分类Dev

无法更新sqlite数据库中的记录

来自分类Dev

数据不会在数据库中更新

来自分类Dev

更新存储在数据库中的JSON数据

来自分类Dev

在Rails中无法在数据库中创建记录

来自分类Dev

无法更新数据库中的对象

来自分类Dev

无法更新数据库中的列

来自分类Dev

无法更新数据库中的行

来自分类Dev

无法更新数据库中的字段

来自分类Dev

对象自动在数据库中更新

来自分类Dev

在数据库中更新/添加事实的最佳方法?

来自分类Dev

行不会在数据库中更新

来自分类Dev

对象自动在数据库中更新

来自分类Dev

在数据库中更新/添加事实的最佳方法?

来自分类Dev

输入字段未在数据库中更新

来自分类Dev

PHP 图像未在数据库中更新

来自分类Dev

更新数据库中的记录

来自分类Dev

数据库设计 - 在数据库中存储 n 周数据并每周更新

来自分类Dev

JPA @Version版本-在数据库中增加,但是使用较小的版本来更新记录

来自分类Dev

根据结果集在数据库中更新或插入记录

来自分类Dev

保存按钮,一旦记录已保存在数据库中,也可以更新

来自分类Dev

如何使用codeigniter更新记录?

来自分类Dev

更新数据库记录

来自分类Dev

CodeIgniter更新数据库

来自分类Dev

无法更新数据库

来自分类Dev

要在数据库中更新的数据(如果存在)-否则应在SQL Server中插入新记录

来自分类Dev

无法更新Kinvey数据库中的数据