Solved

NULL is driving me nuts!

Posted on 2009-07-03
2
179 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now