I want a value to be set to NULL
if nothing is put into the text box in the form I\'m submitting. How can I make this happen?
I\'ve tried inserting \'NULL
if (($_POST['nullfield'] == 'NULL') || ($_POST['nullfield'] == '')) {
$val = 'NULL';
} else {
$val = "'" . mysql_real_escape_string($_POST['nullfield']) . "'";
}
$sql = "INSERT INTO .... VALUES ($val)";
if you put 'NULL'
into your query, then you're just inserting a 4-character string. Without the quotes, NULL
is the actual null value.