Click to See Complete Forum and Search --> : [RESOLVED] Display alt image if $_SESSION not set
NevadaSam
01-15-2007, 04:12 PM
If $_SESSION['image'] is not set, photo.jpg is displayed. That works OK.
If $_SESSION['image'] is set, $_SESSION['image'] is displayed. No problem here.
But if the form has been submitted and no value has been assign to $_SESSION['image'], no image is displayed.
if (!isset($_SESSION['image']) || isset($_SESSION['image']) == '')
echo "<img src='photo.jpg'>";
else
echo " <img src=" . $_SESSION['image']>";
dougal85
01-15-2007, 04:55 PM
if (!isset($_SESSION['image']) || $_SESSION['image'] == '')
echo "<img src='photo.jpg'>";
else
echo " <img src=" . $_SESSION['image']>";
if your one you compared the result of the isset function with ''
However, I would tend to use PHP's empty function
if (!isset($_SESSION['image']) || empty($_SESSION['image']))
echo "<img src='photo.jpg'>";
else
echo " <img src=" . $_SESSION['image']>";
NevadaSam
01-15-2007, 05:28 PM
I came up with your first solution shortly after I made my post:
if (!isset($_SESSION['image']) || $_SESSION['image'] == '')
But I think I will also like to use the empty function. It makes it look like I know what I am doing. :)
Thanks,
Sam
;
Weedpacket
01-21-2007, 11:36 AM
If you use the empty() function, you don't need to use the isset() function as well. If it's not set then it's empty. Contrariwise, if it's not empty then it must be set.
if (!isset($_SESSION['image']) || empty($_SESSION['image'])) is therefore equivalent to if (empty($_SESSION['image']))
NevadaSam
01-21-2007, 11:40 AM
I see what you are talking about. Thanks Weedpacket. I am making that change to my script now.
Sam
;
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.