Forum Moderators: coopster
Here is what I am using:
$query = "INSERT INTO log (wTemp, wSpeed, wDirection, time)
VALUES ( '$weather_temp', '$wind_speed', '$wind_direction', '$time' )";
I have a time field. But I want it to be NULL if no time is entered. If that value is NULL, the above doesn't work unless I remove the '' around $time. But on the other side, if I remove '', then that statement doesn't work if the value isn't NULL.
What is the correct way to make this statement and have it work for NULL or not null?
Thanks,
Mike
function nullifyValue($value) {
return empty($value)?'NULL':"'{$value}'";
}
$query = "INSERT INTO log (wTemp, wSpeed, wDirection, time) VALUES ( '$weather_temp', '$wind_speed', '$wind_direction', ". nullifyValue($time) ." )";