If you want to insert an actual null value instead of the string 'NULL' then you need to drop the quotes.
insert into table (column) values ('NULL')
will insert a string, while
insert into table (column) values (NULL)
will insert an proper null value. Which is not to be confused with this
insert into table (column) values ('')
which inserts a zero-length string. PHP often lets you use nulls and zero-length strings interchangably, but really they are completely different things.
The following code handles all three values correctly:
if (isset($a)) {
$sql_a = "'".mysql_escape_string($a)."'";
}
else {
$sql_a = "NULL";
}
mysql_query("insert into table (column) values ($sql_a)") or die(mysql_error());