This is a tricky topic... When using PHP variables to create a MySQL statement you should NOT define the variable in PHP as data type NULL, but rather as a string data type 'NULL' like Petroz's example. $var = 'NULL';
Now keep in mind, MySQL has it's own syntax rules and using single quotes around 'NULL' in an SQL Statement is taken as a literal string, so...................
Before creating your MySQL Statement you should validate every PHP variable going into the SQL for content and if its not the string NULL nor a number wrap single quotes around as required in MySQL statements:
if ($var != 'NULL' || isnan($var){
$var = "'".$var."'";
}
Then you can create the sql statment worry free of single quotes $sql = "INSERT INTO tTable (ID, Name) VALUES ($var, 'Steve')";