Confused with setting variables to NULL

My website reads a mySQL database and populates a form with all the data. One of the fields is populated with a DATETIME. If the user is new, their guideUpdated is null. When I make changes to the form and click save, it populates the guideUpdated field in the database to ‘0000-00-00 00:00:00’. I’m trying to fix this so if I leave the guideUpdated field empty on my form, then a NULL value goes into the database when the save button is clicked and an update is made. Here is the code I have right before the update is made:

if ($guideUpdated == “0000-00-00 00:00:00” || $guideUpdated == “”) {

$guideUpdated = null;

However, this still doesn’t work. Even though $guideUpdated is blank on the form, it still adds all of the zeros. Can someone point out what I’m missing here?


Your coulm definition in the db table might be set to NOT NULL or have 0’s as the default. If so set the column default to allow NULL.

Also since an empty string (“”) and NULL are not the same thing, your insert sql statement need to insert NULL for the date and not “”