简体   繁体   中英

Update query not working without parameter Codeigniter PHP

I am working with PHP( Codeigniter ) and i want to update those records whose parameter sending, but if i am not sending any parameter then i am getting following error "You must use the "set" method to update an entry" ,I just want if i do not want to update any record but click then error should not come,Here is my code, Where i am wrong?

$saveArr = [];
        if (!empty($this->input->post('first_name'))) {
            $saveArr['first_name'] = $this->input->post('first_name');
        }
        if (!empty($this->input->post('last_name'))) {
            $saveArr['last_name'] = $this->input->post('last_name');
        }

$this->db->where('id', $add_data['user_id']);
$this->db->update('users', $saveArr);

just add one condition

if(count($saveArr) > 0){
   $this->db->where('id', $add_data['user_id']);
   $this->db->update('users', $saveArr);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM