I was told that the previous code wasn’t using parameters even when employing a library that supports it. And that I was using an assignment operator rather than a comparison. Also the true branch is redudant.
Previous Code:
if ($profilepic = $row['profilepic']){
$profilepic = $row['profilepic'];
}else{
$profilepic = "DamjuNoImage";
}
Current Code:
$profilepic = $row['profilepic'];
$noimage = "DamjuNoImage";
if ($profilepic != $row['profilepic']){
echo $noimage;
}
I wanted to double check to see if I fixed the code even though I already tested it.
With the following:
Your if-statement will never do anything. The first line makes
$profilepicequal to$row['profilepic'](whether that’s an empty string, null, or what-have-you), and the condition checks if they are not equal – which will never be the case since you just finished making them equal.If you want to provide a default image, do something like this:
Or written more concisely:
If the profile pic column is empty, we assign the a default value to
$profilepic. From there we can just echo our image.Demo: http://codepad.org/KXuQyVma