CodeIgniter Forums
Empty is not NULL and the Active Record Update class... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Empty is not NULL and the Active Record Update class... (/showthread.php?tid=7336)



Empty is not NULL and the Active Record Update class... - El Forum - 04-03-2008

[eluser]edesign[/eluser]
I have a statement as such

$data['special_case1_answer'] = ($this->input->post('sc_chk_1_1')) ? $this->input->post('sc_answer_1_1') : '';

$this->db->where('ID',$this->input->post('recordID'));
$this->db->update('forms', $data);

WHERE I want the value of the array to go into the Active record update array if a check box is checked, however, when the checkbox is not checked, I would rather have a NULL value inserted into the database, right now I get an EMPTY value, which as any SQL person knows is not the same thing?

So my question is, using the statement above how can I inject a NULL value into a field using the array style UPDATE function of the active record class? Wrapping the NULL value in quotes would simply insert that value into the database, correct?


Empty is not NULL and the Active Record Update class... - El Forum - 04-15-2008

[eluser]ontguy[/eluser]
Just putting null will work.

Code:
$data[’special_case1_answer’] = ($this->input->post(’sc_chk_1_1’)) ? $this->input->post(’sc_answer_1_1’) : null;