Your variable $pic probably holds a null value. If you select something from a database and there is noting in that field, then the database returns a NULL. A NULL isn't the same thing as "", empty(), or even isset(). NULLs cause lots of problems with code like this. One check you can do is to see if the length of the variable is greater than 1, as long as the field you are returning will always have more than 1 character in it this should work for you. A check to see if it's longer than 0 might work also, but it's hard to tell with NULL values.