note 60723 added to language.types.null

From: Date: Sun, 15 Jan 2006 05:53:52 +0000
Subject: note 60723 added to language.types.null
Groups: php.notes 
Request: Send a blank email to php-notes+get-101779@lists.php.net to get a copy of this message
Discovered something probably worth mentioning. I had a form that had several values that didn't have to be set. I wanted to use the word "NULL" as a word (as opposed to the NULL constant) to go into the SQL statement when creating a new record. If I do a check based on the variable having no value: if ($array['var'] == "") { $array['var'] = "NULL"; } Then $array['var'] contains the word "NULL" the way I want it to, BUT I have to be careful with the sql statement (more on this in a moment) On the other hand, if I check via !isset() if (!isset($array['var'])) { $array['var'] = "NULL"; } It treats NULL as the constant and unsets the variable. In the SQL, if I am inserting and put it in as is: $sql = "INSERT INTO mytable VALUES(NULL, ".$array['var'] .", ' ".$array['some_other_var'] ." ')"; the word NULL replaces $array['var'] as it should, but if I enclose the variable in single quotes (because maybe that variable, if it's set, will contain a space) $sql = "INSERT INTO mytable VALUES(NULL, ' ".$array['var'] ." ', ' ".$array['some_other_var'] ." ')"; again, it treats NULL as the constant NULL instead of the word. This seems inconsistent--one would have thought that enclosing it in double quotes would say I want the letters NULL as opposed to the constant, and I'll bug report it as well but wanted to mention it here for other users. ---- Manual Page -- http://www.php.net/manual/en/language.types.null.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60723 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60723&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60723&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60723&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60723&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60723&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60723&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60723&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60723&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101779) next »