Deepashika Deepashika - 4 months ago 19
PHP Question

How to retrieve image from database and display image on the web page

I have inserted image into database and store name in the table.
my image is saved in a folder named 'Uploads'.
Now need to retrieve image from the databse and display it. when I try to display It only shows the image name which is taken from my table.but it does not show the image.

retrieving code is given below

$sql="SELECT * FROM candi_profile WHERE can_email='{$_SESSION['usr_email']}'";

$result=mysqli_query($con,$sql);
if(!$result) die(mysqli_error($con));
<div class="container">

<!-- Page Header -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Employer Dashboard

</h1>
</div>
</div>
<!-- /.row -->

<!-- Projects Row -->

<div class="row">
<div class="col-md-4">
<?php
while($rows=mysqli_fetch_array($result)){
$c_id = $rows['can_id'];
var_dump($c_id);
?>

<p class="lead"><?php echo $rows['can_name'] ?></p>
<div class="profile-sidebar">
<!-- SIDEBAR USERPIC -->

<div class="profile-userpic">
<p class="lead">
<?php echo $rows['pic_name'] ?></p>
</div>

<!-- END SIDEBAR USERPIC -->

<!-- SIDEBAR USER TITLE -->
<div class="profile-usertitle">
<div class="profile-usertitle-name">
Marcus Doe
</div>
<div class="profile-usertitle-job">
<?php echo $rows['can_city'] ?>
<i class="glyphicon glyphicon-map-marker">
</i>
</div>

<div class="profile-usertitle-job">
<i class="glyphicon glyphicon-envelope"></i>
<?php echo $rows['can_email'] ?>
</div>

<div class="profile-usertitle-job">
<?php echo $rows['can_country'] ?>
</div>
</div>
<!-- END SIDEBAR USER TITLE -->

<!-- SIDEBAR BUTTONS -->
<div class="profile-userbuttons">
<hr>
</div>

<!-- END SIDEBAR BUTTONS -->
<!-- SIDEBAR MENU -->

<?php
}
?>
</div>


enter image description here
enter image description here

Answer

you can use this code to retrieve image from database

<?php
include 'connection.php'
?>
<?php

$result = mysql_query("SELECT * FROM table") or die(mysql_error()); 


?>

<table border="1" cellpadding="5" cellspacing="5">
<tr> <th>Image</th></tr>

<?php

while($row = mysql_fetch_array($result)) {

$id = $row['id'];

?>
    <tr>

        <td><img src="uploads/<?php echo $row['pic_name'];?>" alt=" " height="75" width="75"></td>

   </tr>

<?php   
} 
}

?>
</table>