[thelist] PHP to enter NULL into MySQL

fstorr fffrancis at fstorr.demon.co.uk
Tue Sep 2 13:15:20 CDT 2003


Hi all

Thanks for yesterday's help - most gratefully received + worked like a 
charm.  Onwards....

I'm using a PHP front end to update a MySQL db.  I'm trying to get it to 
enter a NULL value in certain fields, but not having much luck.

I've got this:

if (isset($_POST['term']))

     {
	$term = $_POST['term'];
     }
else
     {
	$term = NULL;
     }

then a SQL insert statement:

INSERT INTO 'definition'('term') VALUES ('$term')

This works fine if there is a value present, but if there isn't then it 
just enters nothing into the MySQL row.  Quoting the word NULL obviously 
makes it into a string, so that doesn't work.

How do I get it to actually put a NULL value in?

Regards

Francis






More information about the thelist mailing list