petehallw petehallw - 8 months ago 26
PHP Question

PHP echo to display image HTML

I am trying to display an image on my webpage using a PHP script to determine which image is displayed.
The image link is as follows:

<a href="gallery.php?image=image01">......</a>

My PHP script is thus:

$result = $_GET['image'];
echo '<img src="images/gallery/'.$result.'.jpg">';

So what I am trying to achieve in terms of HTML is:

<img src="images/gallery/image01.jpg">

The result I am getting is '"; ?>' displayed on the page.
Any help would be much appreciated!


I would change the gallery.php to this:

<?php $result = $_GET['image']; ?>
<img src="images/gallery/<?php echo $result; ?>.jpg">

That would simply it a little bit. You should echo out the result to see what you are getting when the variable is passed to the gallery page.