I have this php query for a mysql db which collects basic info about pupils. There are three date fields - dob, doe, and dol - which I want the user to be able to leave blank or fill in yyyy-mm-dd.
INSERT INTO pupil_data (first_name,second_name,gender,registration,dob, doe, dol, ethnicity, eal, pup_prem, pup_prem_plus)
VALUES ('aa','aa','male','kingfisher','','','','White British','yes','yes','yes' )`
The phpmyadmin sql editor comes back with #1292 - Incorrect date value: '' for column 'dob' at row 1
I have set the table up like this:
dob: type=date, null=no, default=1900-12-01
If I put dates like '2006-04-14' into the '' then it works. How can I get it to allow the user to leave it blank?
Thanks
A blank and NOT NULL date
field should be '0000-00-00':
INSERT INTO pupil_data (first_name,second_name,gender,registration,dob, doe, dol, ethnicity, eal, pup_prem, pup_prem_plus)
VALUES ('aa','aa','male','kingfisher','0000-00-00','','','White British','yes','yes','yes');
If you want to allow an empty string as a date
or datetime
value, you need to set the ALLOW_INVALID_DATES
SQL mode. It will then convert any invalid date to 0000-00-00
.