[eluser]rvillalon[/eluser]
What's the proper way of saving checkboxes into a database?
In my database, I have a checkbox field that I set as NOT NULL tinyint(1)
I create the checkbox as follows:
$sale_option = array(
'name' => 'sale',
'id' => 'sale',
'value' => '1',
'checked' => FALSE,
);
<?php echo form_checkbox($sale_option); ?>
I validate it with:
$this->form_validation->set_rules('sale', 'On Sale', 'trim|xss_clean|integer');
But when I save it into the DB and it's unchecked, it gives me an error. I guess because it's NULL? Should I just make the field NULL instead of NOT NULL?