Twenty-five years ago I could program in Basic, so I understand IF-THEN statements. However, there is obviously something I am doing incorrectly to make this script work?
The ELSE works fine, but the IF does not produce the desired results.
<?php
$imgname=$profile["imgname"];
if (!empty($imgname))
{
$pic="$siteaddress/files/"."$defaultpic";
$dimensions = resize($pic);
echo "<img src=\"$pic\" width=\"$dimensions[0]\" height=\"$dimensions[1]\">";
}
else
{
$pic = "$siteaddress/files/".$profile["imgname"];
$dimensions = resize($pic);
echo "<img src=\"$pic\" width=\"$dimensions[0]\" height=\"$dimensions[1]\">";
}
?>
What should happen:
If the condition is satisfied, an image called smiley.jpg defined in my config.php as
//Default image
$defaultpic="smiley.jpg";
should appear. Else it searches the database to find the ["imgname"].
So, in my mind, if $imgname is empty, then the URL to the default image should be http://ccea.socialstudies4u.com/portfolio/files/smiley.jpg and that should be printed with the first ECHO state as a defined 200 X 200 image.
However, with this code, if there is not an image I get the proper sized image placeholder and the dreaded Red X. If there is an image in the Dbase, it appears without a problem.
What am I doing wrong?
Marc
PS. In the config.php
$siteaddress ="http://ccea.socialstudies4u.com/portfolio/";
and the end slash must be there.