0

Getimage.php

<?php
$hostname="localhost";
$username="root";
$password="tiger";

/* @var $dbhandle type */
 $dbhandle = \mysqli_connect($hostname, $username, $password) 
 or die("Unable to connect to MySQL");

/* @var $select type */
$select= \mysqli_select_db($dbhandle,"sample")
     or mysqli_error($dbhandle);
 /* @var $itemId type */
$itemId= (\filter_input(\INPUT_GET,'name'));
$sql="select img from starterveg where itemId=$itemId";
$res2=mysqli_query($dbhandle,$sql);
$row= mysqli_fetch_assoc($res2);
mysqli_close($dbhandle);
header("Content-type: image/jpeg");
echo $row['img'];
?>

<body>
<img src="Getimage.php?itemId=oepsv1086" alt="image" id="img1">
</body>

> I'm not able to display the image from database into the html for.Instead the alt message only appears inside the html form

user3436338
  • 17
  • 1
  • 7

1 Answers1

0

Try in your getimage.php

    header("Content-type:image/jpeg");
    stripslashes ($row['img']);

    echo $row['img']; 

***storing image in DB is not recommended.*

Reference

EDIT 2 >>

$itemId= (\filter_input(\INPUT_GET,'name')); 

this should be

$itemId= (\filter_input(\INPUT_GET,'itemId')); #as you are passing itemid in get

EDIT 3>>

You were missing single quotes (') in where query , that was causing errors

it should be

$sql="select img from starterveg where itemId='$itemId'";
Community
  • 1
  • 1
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45