Assuming that column MY_TABLE.MY_NUMERIC_FIELD allows NULLs:
INSERT INTO MY_TABLE (MY_NUMERIC_FIELD, MY_OTHER_FIELD) VALUES ('',
'some_other_value')
will insert a 0 into the column MY_NUMERIC_FIELD in MySQL and many other
databases.
To insert NULL, the SQL must read
INSERT INTO MY_TABLE (MY_NUMERIC_FIELD, MY_OTHER_FIELD) VALUES (NULL,
'some_other_value')
Hence when you build the SQL statement in PHP, check the value that is to be
inserted into MY_NUMERIC_FIELD. If it is NULL as per your requirement, use
the second form of SQL.
You've said is_null($my_form_variable) returned FALSE though as per your
requirement it should have been NULL. Try using empty():
if (empty($my_form_variable) || ! is_numeric($my_form_variable)) {
$value_for_sql = 'NULL';
} else {
$value_for_sql = $my_form_variable;
}
$sql = "INSERT INTO MY_TABLE (MY_NUMERIC_FIELD, MY_OTHER_FIELD) VALUES
($value_for_sql, '$my_other_form_variable')";
mysql_execute($sql);
/* etc */
Hope this helps!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]