codeigniter - invalid Invalid argument supplied for foreach() in controller -


i have problem invalid argument supplied foreach(); here controller:

public function insertsebab(){       foreach($this->input->post('id_konsultasi') $se)      {          $data = array(         'id_konsultasi'     =>$se,         'kd_sebab'      => $this->input->post('kd_sebab')                );          $konsultasi = $this->class_model->insertsebab($data);         $json =$konsultasi;          echo json_encode($json);      }  } 

where wrong code,how resolve it?

try

public function insertsebab() {      if (is_array($this->input->post('id_konsultasi')) || is_object($this->input->post('id_konsultasi'))) {         foreach ($this->input->post('id_konsultasi') $se) {              $data = array(                 'id_konsultasi' => $se,                 'kd_sebab' => $this->input->post('kd_sebab')             );              $konsultasi = $this->class_model->insertsebab($data);             $json = $konsultasi;              echo json_encode($json);          }     }else{         //do if condition not satisfied or null data     } } 

what have done check if $this->input->post('id_konsultasi') array or object, when $this->input->post('id_konsultasi') empty not return error


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -