0

I have stored several images in my database and now i am trying to retrieve them. The way my script is set up is one user would have would have a selection of information and images to go with that. So the code below shows how an image would display along with the price, car and details. Currently the images are not displaying and i am getting one of those question marks in a diamond shape error. Any ideas?

The images in the database are stored as a BLOB, MIME type image/jpeg

       form method="post" action="booked.php">
  <table>
  <?php while($row=mysql_fetch_assoc($result)) { ?>
    <tr>
      Images: <img style="width: 130px; height: 100px" alt="<?php echo $row['car']; ?>" src="image/<?php echo $row['img']; ?>" /></td>
      Car: <input type="text" name="car"  value="<?php echo $row['car']; ?>" readonly> 
      Details: <input type="text" name="details" value="<?php echo $row['details']; ?>" readonly>
      Price: <input type="text" name="price" value="<?php echo $row['price']; ?>" readonly>
      <input type="radio" name="selected_car" value="<?php echo $row['car']; ?>" /><br>
      <br /><br /><br />

    </tr>
  <?php } ?>

  </table>

3 Answers3

0

Are you storing the file name or the actual file? If it's the actual file you need to write a script to get the data from the DB and present it as output. Something like:

<?php $img = file_get_contents($row['img']); echo $img;

0

To display images in html you need to use the img tag. The src of the image data needs to be a url.

You can't just return the data and expect it to display. People typically write a seperate script that just returns the image data with the mime type set using the header() function.

<img src="getimage.php?id=<?php echo $row['id'] ?>">

This supposes that you are actually storing the image data in a binary field in your database table.

gview
  • 14,876
  • 3
  • 46
  • 51
0

If you really want to paste all the image data in the HTML, you need to base64-encode it. See how here: displaying an image stored in a mysql blob But I would strongly suggest that you do like gview says: write a separate php script to just get the image. It has to look something like this:

<?php
    header('Content-type: image/jpeg');
    $id = $_GET["id"];
    ... get the image from database by $id and echo it ...
?>

... even better - don't store the images as BLOBs. Just store them as files and only store the file names in the database.

Community
  • 1
  • 1
Mikkel
  • 3,284
  • 2
  • 18
  • 20