How to update existing record using codeIgniter

那年仲夏 提交于 2019-12-24 15:08:52

问题


I have a table like this: id, image, user_id.

The user_id is saved from the session. The same user wants to update his profile picture means, how it will update?

This Is Controller Function

public function save() {

   $session_data = $this->session->userdata('logged_in');
   $uid= $session_data['id'];

   //print_r($uid);exit;

   $url = $this->do_upload();
   $this->load->model('user_model');
   $this->user_model->save($url,$uid);

   echo '<script>alert("You Have Successfully Uploaded your Profile Picture!");</script>';

   redirect('/home/');
}

This Is Model

public function save($url, $uid){
    $this->db->set('image', $url);
    $this->db->set('user_id', $uid);
    $this->db->insert('tbl');
    return true;
}

How can I update this query?


回答1:


You can do something like the following:

$upd_data = array(
   'image' = $url,
);

$this->db->where('user_id', $uid)
         ->update('tbl', $upd_data);


来源:https://stackoverflow.com/questions/33253589/how-to-update-existing-record-using-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!