I have a web form to update a date in MySQL. Sometimes the entry will be NULL. When it is NULL, I have to format the update as an integer. When it is not NULL, I have to format the update as a string.
For example:
The issue isn't with MySQL, it is with my ability to manipulate the variables in PHP.
I'm using something like the following:
For example:
Code:
//The date is NULL
UPDATE table SET date=NULL
//The date is a date
UPDATE table SET date='2009-01-28'
The issue isn't with MySQL, it is with my ability to manipulate the variables in PHP.
I'm using something like the following:
Code:
//If there were just one data type, I could just use
$query = UPDATE table SET date=$_POST[date];
//But since there are two types, I'm trying
if (is_null($_POST['date'])) {
//That doesn't work because it isn't picking up the NULL
//So I try
$date=$_POST[date];
if ($date == 'NULL') {
$date=$date;
} else {
$date=$_POST['date'];
}
$query = UPDATE table SET date=$date;
//This works if it is NULL, but if a date is entered like 1945-01-01 it tries to update with the integer 1943.