Welcome Guest, Not a member yet? Register   Sign In
Error when INSERT empty date on MySQL field with Active Record
#1

[eluser]Massimiliano Marini[/eluser]
Hi all,

In my form I've a textbox where it is possible to insert a date but it's optional.

When I do:

Code:
$event = array(
  'name' => $this->input->post('name'),
  'date_event' => $this->input->post('date_event')
);

$this->db->insert('events', $event);

I got this error:

Code:
A Database Error Occurred

Error Number: 1292

Incorrect date value: '' for column 'date_event' at row 1

INSERT INTO `events` (`name`, `date_event`) VALUES ('Foo', '');

My MySQL table is:

Code:
create table event(
  name varchar(128),
  date_event date default null, // I also have tried: null default '0000-00-00' nut nothing
);

but nothing, I can't insert my data into the table.

Why?


Messages In This Thread
Error when INSERT empty date on MySQL field with Active Record - by El Forum - 03-24-2011, 07:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB