here is the code
<?php
session_start();
if(!isset($_SESSION['user_name']))
{
header('Location: login.php');
}
$conn = mysql_connect("localhost", "root", "") or die("Can no connect to Database Server");
?>
<html>
<head>
</head>
<body>
<center>
<div id="ser">
<form action="" method="post">
<label for="file">Card No:</label>
<input type="text" name="card_no" id="card_no" class="fil" onKeyUp="CardNoLength()" onKeyDown="CardNoLength()" onKeyPress="CardNoLength()"/>
<input type="submit" name="search" value="Search" class="btn" onClick="return CardNoLengthMIN()"/>
</form>
</div>
</center>
<br/><hr style="border: 1px solid #606060 ;" />
<center><a href="index.php">Home</a></center>
<br/>
<center>
<?php
if(isset($_POST['card_no']))
{
if($conn)
{
if(mysql_select_db("img_mgmt", $conn))
{
$sql = "select * from temp_images where card_no='".trim($_POST['card_no'])."'";
$result = mysql_query($sql);
$image = mysql_fetch_array($result);
if(isset($image['card_no']))
{
//echo "<img src=\"".$image['file_path']."\" alt=\"".$image['card_no']."\" width=\"250\" height=\"280\"/>";
header("Content-type: image/jpeg");
echo $image['img_content'];
}
else
{
echo "<p style=\"color:red;\">Sorry, Your search came with no results ! <br/> Try with different card number";
}
}
else
{
echo "Database selection error: ".mysql_error();
}
}
else
{
echo "Could not connect: ".mysql_error();
}
}
?>
</center>
</body>
</html>
But it after executing the script it shows:
Cannot modify header information –
headers already sent by (output
started at
C:\xampp\htdocs\img\search.php:61) in
C:\xampp\htdocs\img\search.php on line
77
If you have save the content of the image in the database you can use a
data:uri do show this content in a<img />tag. This allows you to embed content of different mime type in another content, see data URI scheme.But you shouldn’t really save any files (regardless of image or not) in the database. Files belongs to the filesystem, as the name already suggest. You get a huge overhead in saving files in the database. Specially for images you need (maybe) a php script which loads the image, eg. if you use something like
<img src="showimage.php?id=5" alt="..." />. For each image you need to call an additional php script, and you gain nothing. Everyone will tell you its better to save the files in the filesystem and load it via the filesystem as normal. So you use tags like<img src="images/foobar/xyz.png" alt="..." />instead. Even the “I don’t want any ‘broken links’ to images in my database” argument doesn’t count as you simply use the ID inside the path and usefile_exists()to check if an image link is valid or not.