• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
You must use the "set" method to update an entry.

#1
i have this error on update query
You must use the "set" method to update an entry.
codeigniter version 3.1
how to fix it?

controller

PHP Code:
public function ajax_update()
 
   {
 
       $this->_validate();
 
       if ($this->input->post('remove_photo') AND empty($_FILES['photo']['name'])) {
 
           $data['error_string'][] = 'انتخاب عکس اجباری است';
 
           $data['inputerror'][] = 'photo';
 
           $data['status'] = FALSE;
 
       }
 
       $data = array(
 
           'title' => $this->input->post('title'),
 
           'sub_title' => $this->input->post('sub_title'),
 
           'message' => $this->input->post('message',FALSE),
 
           //'captcha' => $this->input->post('captcha'),
 
           'tarikh' => time("NOW")
 
       );


 
       if ($this->input->post('remove_photo')) // if remove photo checked
 
       {
 
           if (file_exists(base_url() . 'assets/img/' $this->input->post('remove_photo')) && $this->input->post('remove_photo'))
 
               unlink(base_url() . 'assets/img/' $this->input->post('remove_photo'));
 
           $data['image'] = '';
 
       }

 
       if (!empty($_FILES['photo']['name'])) {
 
           $upload $this->_do_upload();

 
           //delete file
 
           $person $this->person->get_by_id($this->table$this->input->post('id'), $this->where);
 
           if (file_exists(base_url() . 'assets/img/' $person->image) && $person->image)
 
               unlink(base_url() . 'assets/img/' $person->image);

 
           $data['image'] = $upload;
 
       }
 
       $where = ['id' => $this->input->post('id'), 'position' => $this->position];
 
       print_r($data);
 
       $num $this->person->update($this->table$where$data);

 
       $this->logfile->message('product''''update id'.$this->input->post('id'));
 
       echo json_encode(array("status" => TRUE'number affected rows' => $num));
 
   

model
PHP Code:
public function update($table$where$data)
 
   {
 
       $this->db->where($where);
 
       echo $this->db->get_compiled_update($table$data);
 
       return $this->db->affected_rows();
 
   
Reply

#2
Your question is?
Reply

#3
(11-26-2016, 04:48 PM)ciadmin Wrote: Your question is?

i get the error on update query!
my question is how to fix this error?
Reply

#4
PHP Code:
public function update($table$where$data)
{
 
   $this->db->set($data);

 
   $this->db->where($where);
 
   echo $this->db->get_compiled_update($table$data);
 
   return $this->db->affected_rows();

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.