I came up with the following script for displaying an uploaded picture on a webpage but for some reason I can’t pinpoint, the picture won’t be displayed. I checked my database from php myadmin and sure enough, the picture was successfully uploaded but somehow, the picture won’t be displayed. So here is the display script. I named it display_pic.php
<?php
//address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
//authenticate user
//Start session
session_start();
//Connect to database
require ('config.php');
//address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
//include the config file
require('config.php');
$image = stripslashes($_REQUEST[imname]);
$rs = mysql_query("SELECT* FROM images WHERE member_id = '".$_SESSION['id']."' AND image_cartegory = 'main' ");
$row = mysql_fetch_assoc($rs);
$imagebytes = $row[image];
header("Content-type: image/jpeg");
print $imagebytes;
?>
The tag on the html page that’s supposed to display the picture reads something like this
And just in case this might help, I will include the image upload script below, which I think worked just fine because my values were successfully inserted into the database.
<?php
//This file inserts the main image into the images table.
//address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
//authenticate user
//Start session
session_start();
//Connect to database
require ('config.php');
//Check whether the session variable id is present or not. If not, deny access.
if(!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) {
header("location: access_denied.php");
exit();
}
else{
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO images (member_id, image_cartegory, image_date, image) VALUES ('{$_SESSION['id']}', 'main', NOW(), '$data')";
$results = mysql_query($query);
// Print results
print "Thank you, your file has been uploaded.";
}
else {
print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close();
} //End of if statmemnt.
?>
So any insights as to why the script fails to display the image? Any help is appreciated.

