Search code examples
phpvariablesimagesrc

img src won't work with php variables


<a href="'.$productLink.'" alt="'.$productName.'">
<img src="'.$productImg1URL.'" alt="'.$productName.' '.$productType.' ">
</a>

Hello the img src is actually in a different directory /images

I know this is probably super easy but Ive spent an hour on it and nothing. The page works but doesn't show the directory. Please help the rookie. I took out the < in front of the a href and img src couldn't make the page display


Solution

  • Job #1 when you have a problem with code that is generating HTML, is look at the output source and compare it with what you expect. I've had problems like this before and they usually vanished when I stopped thinking about the PHP code, and looked at the actual output.

    What is the content of $productImg1URL - and if the images that it's referencing are in the URL starting /images/ - does that start $productImg1URL. If it's just the name of an image, but without the path - you have to put that into place.