Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you send NULL as a variable from PHP to SQL?

Tags:

php

mysql

I want to send a value of "NULL" to a column in mySQL.

   $ParentEventID = "NULL";

   mysql_query("UPDATE events SET 
     ParentEventID = '$ParentEventID'");

The column keeps defaulting to "0". I have the column set to accept NULL and I can edit the cell with the NULL check box.

I need to not set the default to NULL because it may effect code in other places.

like image 532
Joel Avatar asked Jun 18 '11 20:06

Joel


1 Answers

You are on the right track making "NULL" a string. If you need to set it NULL, then remove the qoutes around $ParentEventID.

mysql_query("UPDATE events SET ParentEventID = $ParentEventID");

However, before doing so make sure that the value of $ParentEventID === NULL.

like image 71
Michael Berkowski Avatar answered Oct 07 '22 03:10

Michael Berkowski