I am building a fruit store website.
Currently, I wanna ask to my customers what kind of fruits they love.
So, I created several checkbox options for them.
<form action='customer_favorite' method='POST'>
<input type='checkbox' name='chk[]' value='banana' />
<input type='checkbox' name='chk[]' value='mango' />
<input type='checkbox' name='chk[]' value='apple' />
<input type='checkbox' name='chk[]' value='orange' />
<input type='checkbox' name='chk[]' value='kiwi' />
<input type='submit' value='submit' />
I don't know how many checkboxes they will check.
When it posts to my server, I want to get the result like this.
apple, orange, kiwisecond customer would choose four of them.
banana, mango, apple, orange
and I will put this data into my db like this.
$data = array(
'fav_fruits' = $this->input->post('chk')
);
$this->db->insert('customer', $data)
The problem is that I can't get result 'apple, orange, kiwi' like this.
- we don't know how many checkbox values will be there.
- I want to array values like this 'apple, orange, kiwi'