Wen Qing
Wen Qing

Reputation: 111

Displaying Image directly from database

apparently i have issue with displaying the image as it only show me the name of the file, is there anyway for it to display on the webpage right away? Below is my source code along with 2screenshots of my database holding the image and the place where i want it to display at:

<?php

error_reporting(E_ERROR); 

include("global.php");


session_start();

$receipt = $_GET['receipt'];
$userid = $_SESSION ['userid'];
if (isset($_SESSION['userid']) == false) 
{
    header ("Location: login.php");
}

$mysqli = new mysqli(spf, dbuser, dbpw, db);
$stmt = $mysqli->prepare("SELECT receipt, date, time, pick, dropoff, userid, carno, cost, branch, area, image FROM items where receipt=?");
$stmt->bind_param("s", $receipt);
$stmt->execute();
$stmt->bind_result($receipt, $date, $time, $pick, $dropoff, $userid, $carno, $cost, $branch, $area, $image);

while ($stmt->fetch()) {
    echo "<table border='1' style='width:40%'>";
    echo "<td>";
    echo "<b>Receipt ID: $receipt</b>";
    echo "<br><br>";
    echo "$image";
    echo "<br><br>";
    echo "<b>Date of Travel: $date</b>";
    echo "<br><br>";
    echo "<b>Time of Travel: $time</b>";
    echo "<br><br>";
    echo "<b>Pick Up Location: $pick</b>";
    echo "<br><br>";
    echo "<b>Drop Off Location: $dropoff</b>";
    echo "<br><br>";
    echo "<b>Area of DropOff: $area</b>";
    echo "<br><br>";
    echo "<b>Cost of Trip: $cost</b>";
    echo "<br><br>";
    echo "<b>User ID (NRIC): $userid</b>";
    echo "<br><br>";
    echo "<b>Branch of Officer: $branch</b>";
    echo "</td>";
}

echo "</table>";

$stmt->close();
$mysqli->close();

?>

Preview: location where i want to display my image

An image file name inside the database

Upvotes: 2

Views: 49

Answers (2)

Devsi Odedra
Devsi Odedra

Reputation: 5322

Use <img> tag as below

 echo "<img src=$image>"

Upvotes: 3

Melcma
Melcma

Reputation: 618

Try this:

echo "<img src='$image'>";

Learn about img

Upvotes: 1

Related Questions