- This is the model:
public function saveShifts($data) {
$this->db->db_debug = FALSE;
$error = NULL;
if (!$this->db->insert('shifts', $data)) {
$error = $this->db->error();
}
return $error;
}
- This is the controller:
public function saveShifts(){
$data = array (
'user_id' => $_SESSION['id'],
'day' => $this->input->post('day'),
'time' => $this->input->post('time'),
);
$this->Shifts_model->saveShifts($data);
}
- This is the view:
I can't post it cause it disappears when I post it.
So the view contains a form with radio buttons selection for each day of the week. You can choose either morning or evening.
MySql DB structure is: when the keys are user_id
and day
+---------+---------+--------+
| day | time | user_id|
+---------+---------+--------+
| Sunday | morning | 1 |
+---------+---------+--------+
| Monday | evening | 1 |
+---------+---------+--------+
Well, I have a problem inserting multiple rows to DB using one query. In the view, the form contains radio buttons for each user to choose from for each day. It is only inserting one row (that last one) every time.