-1

Hey guys am having trouble displaying an image from the DB on a web page.

Am using this to display

echo "<img

src=image.php?"' width=300 height=270/>";

here is my image.PHP

<?php
session_start();
$con1=mysql_connect("localhost","root","roots");
mysql_select_db("blog",$con1);
if(!$con1)
{
  die('could not connect'.mysql_error());
}

$q="select image from data where Number=1";
$result= mysql_query($q,$con1);
if($result)
{
$row=mysql_fetch_array($result);
header("content-type:image/jpeg");
echo $row['image'];

}
else
{
  echo mysql_error();
}
?>
  • Welcome to StackOverflow. This is *almost* a good question. If you were to add more description of what happens when you try to run this code, you would improve it. – O. Jones Jun 04 '14 at 12:04
  • possible duplicate of [I need my PHP page to show my BLOB image from mysql database](http://stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database) – Jay Blanchard Jun 04 '14 at 12:04
  • The code is supposed to get an image stored in the database and display it on index.php – user3706858 Jun 04 '14 at 12:06
  • 1
    image tag is not `` it's `` – Dexa Jun 04 '14 at 12:10

1 Answers1

-1

echo $row['image']; simply display the data's fetched from DB.

Supposed your image column holds data like this http://domain/project/images/img.jpg

echo '<img src="'.$row['image'].'" width=300 height=270 />' ;
Ranjith
  • 2,779
  • 3
  • 22
  • 41