I have variable set to NULL that im trying to insert into a database but for some reason they keep getting submitted as '0'. Im positive that column im trying to inset into allows NULL and that the default is set to to NULL. Heres my code:
$insert = NULL;
$query = mysql_query("INSERT INTO `table1` (column1) VALUES ('$insert')") or die(mysql_error());
IF you want it to be
NULL
(and you really really still want to usemysqli_*
) in the database you can do the following:But this could lead to nefarious SQL injection and is not recommended.
See Bobby Tables
So: all in all you should be using prepared statements.
You can use MySQLi like so:
Try this for static query:
Using Variable :
Try without the quotes;
The query should be;
INSERT INTO
table1
(column1
) VALUES (NULL);