Solved

NULL is driving me nuts!

Posted on 2009-07-03
2
182 Views
Last Modified: 2013-12-13
In my database, these three fields are defined as SMALLINT:
phone2_ac, phone2_ex, phone2_num

When inserting a recored into the database, I found that if my form fields for these were blank, this was what I had to do:
$phone2ac = 'NULL';
$phone2ex = 'NULL';  //if field is text, then you don't use the quotes
$phone2num = 'NULL';
I then used $phone2ac, $phone2ex, and $phone2num in my INSERT statement. If I omitted the quotes from 'NULL', I got an error on the insert.
My insert was like this:
INSERT INTO tblmine phone2_ac, phone2_ex, phone2_num VALUES ($phone2ac, $phone2ex, $phone2num);

All fine so far. In my database, the values are NULL.

Now, I do this:

if (!is_null($phone2ac) || !is_null($phone2ex) || !is_null($phone2num))  {
      $body .= "Other Phone: " . $phone2ac . "-" . $phone2ex . "-" . $phone2num . "\n"; }

When all three fields are null, $body is getting set. I do not understand why?

It's been a long day ...
0
Comment
Question by:alicia1234
2 Comments
 
LVL 9

Accepted Solution

by:
pmessana earned 125 total points
ID: 24775271
The problem is that the values are not null, you set them to word "NULL", you didn't set the variables NULL.

You could do this:

if ($phone2ac!='NULL') || l($phone2ex!='NULL') || l($phone2num!='NULL'))  {
      $body .= "Other Phone: " . $phone2ac . "-" . $phone2ex . "-" . $phone2num . "\n"; }
0
 

Author Comment

by:alicia1234
ID: 24775314
Thanks, that worked.



if ( $phone2ac != 'NULL' || $phone2ex != 'NULL' || $phone2num != 'NULL' )  {
	$body .= "Other Phone: " . $phone2ac . "-" . $phone2ex . "-" . $phone2num . "\n"; }

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question