Solved

NULL is driving me nuts!

Posted on 2009-07-03
2
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …

691 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