Page 1 of 1

Simple Question -> empty() or is_null()

Posted: Fri Sep 01, 2006 2:56 pm
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.

Posted: Fri Sep 01, 2006 3:53 pm
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