Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

test for NULL

Posted on 2011-09-08
3
Medium Priority
?
263 Views
Last Modified: 2012-05-12
How do you test for a null value in php?

The following statement seems to be failing:

if (  $var !="NULL" )  

0
Comment
Question by:pillmill
[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
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 36505130
For EQUAL:
if( $var === NULL )
{
 ...
}

OR
if( is_null($var) )
{
...
}


For NOT EQUAL:
if( $var !== NULL )
{
 ...
}

OR
if( !is_null($var) )
{
...
}
0
 

Expert Comment

by:ajkukla
ID: 36505190
http://www.php.net/manual/en/function.is-null.php

if (is_null($var)) {
   //do something
}
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36505470
I think @hielo gave all the variations.  The reason your version is failing is because the quotes make it a text string and not the named constant NULL.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 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 …
Suggested Courses

604 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