Can't Pass NULL Date from form
Posted 03 March 2006 - 01:39 PM
if ($date === '' or !isset($date)) $date='NULL';
This almost works, but the resultant statement contains the single quotation marks, which cause an error.
INSERT INTO jobs ( JobNumber, DateRcvd, DateEff ) VALUES ( '9999', 'NULL', 'NULL')
Does not work, but
INSERT INTO jobs ( JobNumber, DateRcvd, DateEff ) VALUES ( '9999', NULL, NULL)
This is my actual query:
$query = "INSERT INTO jobs ( JobNumber, DateRcvd, DateEff, ) VALUES ( '$JobNumber','$DateRcvd','$DateEff',)";
If I remove the single quotes from the date values, the nulls are entered correctly but that only works if the field is null. If a date is entered, it doesn't work.
Ahy help will be greatly appreciated.
Posted 03 March 2006 - 04:54 PM
if (DateRcvd == "")
query = ...
elseif(DateEff == "")
Probably not the best approach but the only one i could think of now reading your post.
Posted 03 March 2006 - 07:34 PM
$query = "INSERT INTO jobs ( JobNumber, DateRcvd, DateEff, ) VALUES ( '$JobNumber',$DateRcvd,$DateEff)";
And have PHP add the single quotes if necessary:
$DateRcvd = ($DateRcvd === '' or !isset($DateRcvd)) ? "NULL" : "'$DateRcvd'";
Do the same for $DateEff, if necessary.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users