[eluser]benmanson[/eluser]
Hi,
I am hoping this is something simple that I am doing wrong here. I have a series of checkboxes in a form with values from 1 to 24 ie:
Code:
<input type="checkbox" name="categories[]" value="1"> Investment Banking<br>
<input type="checkbox" name="categories[]" value="2"> Corporate and Institutional Banking<br>
...
<input type="checkbox" name="categories[]" value="23"> Logistics and Distribution<br>
<input type="checkbox" name="categories[]" value="24"> Education<br>
The problem I am having is in storing those values in my database, I only seem to get the first digit of the value, so the checkbox with a value of '24' is being read as '2'.
Here is the code in my controller that grabs the array via the post, and then uses a model to insert it into the database:
Code:
$staff_data['id'] = $this->input->post('id');
$categories = $this->input->post('categories');
if ($categories !== FALSE) {
foreach ($categories as $row) {
$cat_data['cid'] = $row['categories'];
$cat_data['sid'] = $staff_data['id'];
$this->Cms_model->add_lookup($cat_data);
}
}
When I print_r($categories) it outputs the array fine, the problem is in the foreach loop I think, because when I add a line to the loop to output the 'cid' and 'sid' values, it outputs the first digit for 'cid' only.
Hopefully someone can point out the error of my ways...
cheers
Ben