0

The code below is a part of my PHP script, which is supposed to display the product image in front of the product info.

Each image is identified by its product_id. Those IDs which are auto-incremented and received from the MySQL database.

PHP code:

while($row=mysql_fetch_array($result)){
          $ProductName = $row['product_name'];
          $ProductCat = $row['product_cat'];
          $Email = $row['email'];
          $ID = $row['product_id'];
  //-display the result of the array
          echo '<div ><img align="right" src="/project_images/$ID.JPG" width="280" height="125" /></div>';

The images appear corrupted on the browser.

Is it because the images are of the wrong size (possibly too big) or is the code wrong?

Foo L
  • 10,977
  • 8
  • 40
  • 52
Cash Vai
  • 155
  • 1
  • 1
  • 9

1 Answers1

1

Consider replacing the single quotes with doubles and escaping double quotes inside the line, like the following:

while($row = mysql_fetch_array($result)){
    $ProductName = $row['product_name'];
    $ProductCat = $row['product_cat'];
    $Email = $row['email'];
    $ID = $row['product_id'];
    // - display the result of the array
    echo "<div ><img align=\"right\" src=\"/project_images/$ID.JPG\" width=\"280\" height=\"125\" /></div>";

PHP only inserts variables' content into string if you put them to the double-quoted string.

More information on difference between single- and double- quoted strings in PHP could be found here: What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
dnl-blkv
  • 2,037
  • 1
  • 17
  • 22