Solved

NULL is driving me nuts!

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 …
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 look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

810 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