Ghugu Ghugu - 1 month ago 8
PHP Question

Not able to insert the data inside db

I need help i tried everything but nothing works don't know what's the issue. i want as i check then insert if uncheck then delete but my code doesn't insert

if($this->input->post()){

$select_assigned_ids = $this->input->post('assigned_ids[]');
if ($this->form_validation->run() == FALSE) {
foreach($select_assigned_ids as $tlusers){
$data = array(
'user_id' => $tlusers
);
$test = $this->assign_permission_model->insert($data);


}

}
}else{
//Checkbox is unchecked....
$q = 'Delete from assign_permission ';
$this->section_permission_model->qwr($q);
}


It doesn't insert any value in db

Answer

like this code your define array $data remove (,) so insert data

    if($this->input->post()){
    $select_assigned_ids = $this->input->post('assigned_ids[]');
        if ($this->form_validation->run() == FALSE) {
            foreach($select_assigned_ids as $tlusers){
                $data = array(
                            'user_id' => $tlusers
                        );
                $test = $this->assign_permission_model->insert($data);

                } 

    }
    }else{
        //Checkbox is unchecked....
      $q = 'Delete from assign_permission ';
      $this->section_permission_model->qwr($q); 
    }