I am trying to display single image from database in index.php. Database is connected successfully. but, unfortunately, the image didn't show. I don't know where is my mistake in the code. May I have help please. Database name "newss" Table name "main_img" include 4 columns (id(int), title(varchar), source(varchar), image(blob)) my code blow:
//getImage.php
<?php
require_once('connection.php');
if(isset($_GET['id']))
{
$id = mysqli_real_escape_string($_GET['id']);
$query = mysqli_query("SELECT * FROM `main_img` WHERE `id`='$id'");
while($row = mysqli_fetch_assoc($query))
{
$imageData = $row["image"];
}
header ("content-type: image/jpeg");
}
else
{
echo "Error! in retrive the image ";
}
?>
//index.php
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello in the page of displaying the image </h1>
<img src="getImage.php?id=2">
</body>
</html>