Home >Database >Mysql Tutorial >How to Display MySQL Database Images in an HTML Image Tag Using PHP?
Retrieving Images from MySQL Database and Displaying in an HTML Image Tag
Question:
In PHP, you've created a MySQL database with a table that includes a BLOB column for storing JPEG images. You've also written a PHP script, catalog.php, to retrieve the image from the database and display it in an HTML image tag. However, you're experiencing issues accessing the $result variable in your catalog.php script.
Answer:
Directly accessing the $result variable in HTML is not possible. To display the image in the HTML tag, you need to create a separate PHP script to fetch the image data from the database and return it as an image.
Updated catalog.php:
<body> <img src="getImage.php?id=1" width="175" height="200" /> </body>
New PHP Script: getImage.php:
<?php $link = mysqli_connect("localhost", "root", "", "dvddb"); $sql = "SELECT dvdimage FROM dvd WHERE>
How it Works:
The above is the detailed content of How to Display MySQL Database Images in an HTML Image Tag Using PHP?. For more information, please follow other related articles on the PHP Chinese website!