I ve setup a checkbox form (each question has only one checkbox). The form is submitting, but it only sends zeros to mysql--whether the box has been checked or not. How can I get the correct values (1 or 0) sent to mysql?
Built in Codeigniter/mysql.
<><>strong>FORM
<?php echo form_open( addFoo ); ?>
<input type="checkbox" name="foo1" value="" /> //I tried this w/values incl; still zeros
<input type="checkbox" name="foo2" value="" />
<input type="checkbox" name="foo3" value="" />
<input type="checkbox" name="foo4" value="" />
<?php echo form_submit( submit , Save Changes ); ?>
<?php echo form_close(); ?>
CONTROLLER
function addFoo()
{
if ($this->input->post( submit )) {
$id = $this->input->post( id );
$foo1 = $this->input->post( foo1 );
$foo2 = $this->input->post( foo2 );
$foo3 = $this->input->post( foo3 );
$foo4 = $this->input->post ( foo4 );
$this->load->model( foo_model );
$this->foo_model->addFoo($id, $foo1, $foo2, $foo3, $foo4);
}
}
function addFoo($id, $foo1, $foo2, $foo3, $foo4) {
$data = array(
id => $id,
foo1 => $foo1,
foo2 => $foo2,
foo3 => $foo3,
foo4 => $foo4
);
$this->db->insert( foo_table , $data);
}