![]() |
$this->input->post() null /mysql date type issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: $this->input->post() null /mysql date type issue (/showthread.php?tid=56405) |
$this->input->post() null /mysql date type issue - El Forum - 12-17-2012 [eluser]Unknown[/eluser] Hi all, I've got the following code: Code: $data = array( This executes fine however because the 'some_date' column is type 'date' and does not allow NULL values, if a value is not entered in the form this is getting filled as '0000-00-00' because rather than getting sent NULL the database is getting an empty string. I could get around this by doing some sort of conditional on the data before it goes into the $data array to not send data for this cell: Code: if ( $this->input->post('some_date') !== '' ) but it doesn't seem very DRY as I ideally I'd like this behaviour on each array element. Does anyone know how I could possibly achieve this by default or via some sort of filter please? Thanks in advance. $this->input->post() null /mysql date type issue - El Forum - 12-17-2012 [eluser]Aken[/eluser] You could fill your $data array, and then go over it with a loop or an array_map() function to check for empties. Ideally, you will ALWAYS do some sort of filtering / sanitizing / checking on any element that will go into your DB. I think a DRY rule in this syntax is thinking a little too extreme. Sometimes those items will need their own specific checks, so you may find yourself doing various IF checks regardless. $this->input->post() null /mysql date type issue - El Forum - 12-17-2012 [eluser]CroNiX[/eluser] Sounds like it could be fixed with a simple validation callback, applied only to those fields that need it. |