-1

This is my code.

<img src="getimage.php?id=1" alt="Delicious World" />

This is getimage.php

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("db_cupcake");
  $sql = "SELECT image FROM item WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['0'];
?>

I have directly stored the image in the database. I want to load those images in the webpage. Help me out.

bravia473
  • 5
  • 3

3 Answers3

0

You need to echo $row[image]; not echo $row[0];

Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
0

First things first . If you are passing variables in the mysql query , then use quotations .Only then mysql will execute the query . your query :- $sql = "SELECT image FROM item WHERE id=$id"; Instead use this query :- $sql = "SELECT image FROM item WHERE id='$id'"; And to display the image you can use

echo $row['image'];
-1
<?php
$id = $_GET['id'];

// do some validation here to ensure id is safe

$link = mysql_connect("localhost", "root", "", "db_cupcake");  

$result = mysql_query("SELECT image FROM item WHERE id=$id");

$row = mysql_fetch_assoc($result);  

header("Content-type: image/jpeg"); 

echo $row['image'];

mysql_close($link);

?>
php-coder
  • 955
  • 1
  • 12
  • 23
  • Hi, 0 is not string. Please remove single quotes from 0. echo $row[0] is right or $row['image'] – alagu Jul 30 '15 at 07:47