Welcome Guest, Not a member yet? Register   Sign In
Codeigniter passing checkbox array values to mysql database
#4

[eluser]CroNiX[/eluser]
I don't know why you are using an array for this case.

If your checkboxes were like:
Code:
<input type="checkbox" name="fanta" value="1" <?php echo set_checkbox('fanta', '1', FALSE); ?>/>Fanta

Then in your controller you'd just do:
Code:
$data = array(              
        'fanta' => ($this->input->post('fanta') === FALSE) ? 0 : 1,
        //same for other checkboxes...
);

Checkboxes don't get transmitted via $_POST unless they are actually checked. So, if it isn't checked, then input::post('fanta') will be boolean FALSE. If it's boolean false, use a 0, else use 1 as it was checked.


Messages In This Thread
Codeigniter passing checkbox array values to mysql database - by El Forum - 02-25-2014, 08:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB