0

I create php script that shows the Id and the image stored in mysql database, but i can just see the image without the Id, how can i show the image and the id in this php script ?

<?php
$con = mysqli_connect("localhost","root","","othmane") or die(mysqli_error($con));
  
if($_SERVER['REQUEST_METHOD']=='GET'){
$id = $_GET['id']; 
$sql = "SELECT image,image_type FROM images where id = $id";

$r = mysqli_query($con,$sql) or die(mysqli_error($con));;
  
$result=mysqli_fetch_array($r);
header('Content-Type:image/jpeg');
$ss=$result['image_type'];

if ($ss == 'php') {
   echo 'Type of image ' . $result['image_type'];
            echo ( $result['image']);
} else if ($ss == 'android') {
   echo 'Type of image ' . $result['image_type'];
            echo base64_decode( $result['image'] );
        }
  
mysqli_close($con);
}
?>

this is what i get when i execute script :

enter image description here

note : when i remove echo 'Type of image ' . $result['image_type']; from the code the image is properly displayed. but i want to show the image and its type too.

Otmàane Fikri
  • 109
  • 3
  • 14

0 Answers0