2

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

3
  • 2
    use <img> tag. echo "<img src=$image>"; Commented Nov 22, 2017 at 8:51
  • Write an answer @romanreign ! It'll be easier for others to see it (since this is the right answer) Commented Nov 22, 2017 at 8:52
  • @romanreign great thanks it work nicely :) Commented Nov 22, 2017 at 8:52

2 Answers 2

3

Use <img> tag as below

 echo "<img src=$image>"
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

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

Learn about img

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.