I wrote a code to insert input data to database using codeigniter but before inserting, data will go through an if statement to check the input then if condition is met data will be saved.
I was trying to check if the input data is equal to section then parent id must be 0. Else if not section then the $data['type'] entered must be inserted to database and parent id must not be 0. This is my code so far.
$data = array (
'title' => $this->input->post->('title'),
'type' => $this->input->post->('type'),
'description' => $this->input->post->('description')
);
if ($data['type'] == 'section') {
$data['parent_id'] = 0;
} else {
$data['parent_id'] = $this->input->post('parent_id');
$data['type'] = $this->input->post('type');
}
$result = $this->checklist_item_model->put_item($data);
Model
public function put_item ($data) {
$this->db->insert('items', $data);
}