Simple Question -> empty() or is_null()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Simple Question -> empty() or is_null()

Post by seodevhead »

When you query the database and retrieve records that are both NOT NULL and of NULL type, and you want to determine if one of the column's value you retrieved is NULL or something in it like a string, are you supposed to use is_null() or empty() to check the column?

For instance,

Code: Select all

if (!is_null($row['lastName'])) echo $row['lastName'];
- OR -

Code: Select all

if (!empty($row['lastName'])) echo $row['lastName'];
Of course the reason I want to check is because 'lastName' is setup like so in MySQL:

lastName VARCHAR(30) DEFAULT NULL

..and if the user decides not to fill out his last name in the form, then it simply INSERT's a value of NULL for that column in the INSERT query.

Thanks for your help on this matter.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

var_dump() your variable and see if it is actually type NULL or if its just an empty string or whatnot. base your decision off of that
Post Reply