![]() |
Active record 'update' introducing 0 into previously null columns - 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: Active record 'update' introducing 0 into previously null columns (/showthread.php?tid=28398) |
Active record 'update' introducing 0 into previously null columns - El Forum - 03-10-2010 [eluser]richzilla[/eluser] Hi All, Is there anyway to view the SQL that active record produces as im having a bit of a problem with the update function. Basically, whenever the update function is run, two zero's appear in my table in fields that were previously null. The form fields are also null. Does anyone know why this might be happening? Any help would be appreciated, Thanks Active record 'update' introducing 0 into previously null columns - El Forum - 03-10-2010 [eluser]n0xie[/eluser] Code: echo $this->db->last_query(); Or turn on profiler Active record 'update' introducing 0 into previously null columns - El Forum - 03-10-2010 [eluser]danmontgomery[/eluser] I'm guessing that you're just setting the value without checking it: Code: $this->db->set('some_field', $this->input->post('some_field')); Which will return FALSE, or 0 for form fields which are left blank (I'm assuming this is what you mean by null). To solve this you just need to check the value of the field before you set it. Code: if($this->input->post('some_field') != FALSE) { |