faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 46 people (52%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How do I insert a null into mysql using a php var? i.e. '$x' where $x could be null or have a value

May 21st, 2001 17:14
Onno Benschop, Brad Ford, Ben Udall,


Use this construct:
($x?'NULL':$x)
If $x is empty then the text substituted will be NULL, otherwise $x.
Sample:
$x = ($x?'NULL':$x) ;
$select = "INSERT INTO table (myField) VALUES ($x)" ;