trying to save the checkbox 'checked status in my database. I am using codeigniter for this. I add the cehckbox form value to the array as follows:
'treated' => $this->input->post('treated'.$i),
I then write to database passing my array which contains the above input.
this is written to the database as 'on' and works with char/varchar
. if however I change this to bit
or tinyint(1)
it fails with mssql error Conversion failed when converting the varchar value 'on' to data type tinyint.
How can I pass the checked checkbox value as 1
instead of on
?
Thanks in advance.
update
$i=1;
while($i<=$this->input->post('orderlines'))
{
$treatedVal=$this->input->post('treated'.$i)?1:0;
//set the data for line insert start
$data = array(
'treated' => $treatedVal,
);
$this->sales_model->order_lines_insert($data);
$i++;
}