Possible Duplicate:
Insert NULL variable into database
I have a table (log) with Columns:
Seconds: bigint(20) UNSIGNED NULL
IPAddress: varchar(15) NULL
The problem is that whenever the variables are given the value NULL, they are inserted in the columns as an empty string for the IPAddress column and as 0 for the Seconds column, not as NULL.
//PHP 5.3.9//
if(isset($_POST['sec']))
$seconds = mysql_real_escape_string($_POST['sec']);
else
$seconds = NULL;
if(isset($_POST['ip']))
$ipaddress = mysql_real_escape_string($_POST['ip']);
else
$ipaddress = NULL;
$query = mysql_query("INSERT INTO log (Seconds, IPAddress) VALUES('".$seconds."', '".$ipaddress."')", $DbConnectionMyDb);
I've searched all over google, but all the answers assumes that I already know whether the variables $sec and $ip are going to be NULL or not. In my case it depends on the POST data.
Any help is deeply appreciated. Thanks.