Link to home
Start Free TrialLog in
Avatar of alicia1234
alicia1234Flag for United States of America

asked on

NULL is driving me nuts!

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 ...
ASKER CERTIFIED SOLUTION
Avatar of pmessana
pmessana

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alicia1234

ASKER

Thanks, that worked.



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

Open in new window