[eluser]Unknown[/eluser]
Hi all,
I've got the following code:
Code:
$data = array(
'some_date' => $this->input->post('some_date')
);
$this->db->insert( 'my_table', $data );
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') !== '' )
$data['some_date'] = $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.