-2

I am trying to write an html site that shows an image. The image source is defined by:

<img src="<? echo htmlspecialchars($_GET['id']; ?>.jpg">

It doesn't do anything besides generating an ERR_FILE_NOT_FOUNDas it fails to load the ressource, while replacing the source with "1.jpg" renders the image. The href links to example.com/page.html?id=1.

Do I have to include something like <?php $id = $_GET['id']; ?> at the beginning of the body?

Full code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Slideshow Test</title>
    <link rel="stylesheet" href="./style.css">
    <link rel="shortcut icon" href="./img/Shortcut.ico" type="image/ico">

  </head>
  <body class="a12">
  <?php /**$id = $_GET['id']; **/?>
    <div align="center">
                  <tr height="460">
                    <td class="a10" height="460" width="566">
                      <div align="center"></div>
                      <img src="<? echo htmlspecialchars($_GET['id']); ?>.jpg" alt="an image" height="460" border="0">
                    </td>
                  </tr>
    </div>
  </body>
</html>
thraizz
  • 66
  • 8
  • 1
    Well… what's the HTML being generated here, the actual URL that the browser is trying to fetch? Since there's a syntax error in your PHP I'd bet it's not "1.jpg"… – deceze Oct 04 '17 at 10:17
  • 1
    Your code has a typo, you never closed the function call to `htmlspecialchars()`. Also, show what the actual resulting HTML is. – David Oct 04 '17 at 10:18
  • The browser is trying to fetch `%20echo%20htmlspecialchars($_GET[%27id%27]);%20?>.jpg`, why is the php code not resolved ? – thraizz Oct 04 '17 at 10:21
  • Does *any* PHP code on that page work…? – deceze Oct 04 '17 at 10:30

1 Answers1

0

please include php in your code.

replace

<img src="<? echo htmlspecialchars($_GET['id']; ?>.jpg">

with

<img src="<?php echo htmlspecialchars($_GET['id']); ?>.jpg">
deceze
  • 510,633
  • 85
  • 743
  • 889
Moby M
  • 910
  • 2
  • 7
  • 26
  • I fixed that typo. Does my html code need to include a .php file? I thought that it would also work by just including the neccessary php code with `` Tags. – thraizz Oct 04 '17 at 10:27
  • if u want to call a php file externally then u can include it.in this case no need to do this. – Moby M Oct 04 '17 at 10:56