If you open the getpicture.php file directly, passing a valid ID, what is shown in the browser? If it just shows a broken image symbol, or nothing at all, try removing the header("Content-Type: image/jpeg"); line and look at it again. Are the any errors visible? Or anything out of the ordinary?
Since the contents of the getpicture.php file are supposed to be shown as an image, echoing a text message for errors doesn't make much sense either. I would suggest finding an error image, and if there is a problem with showing the real image, show that one instead.
Consider something like this:
<?php
// Turn of error reporting, as it doesn't really do any
// good in this situation. It may be a good idea, though, to
// enable error logging to a file, so you can still catch errors
// that happen in the code.
ini_set("display_errors", false);
/**
* Shows an error image and exits the script.
* @param string $imageName The name of the image file to show.
*/
function showError($imageName="error") {
$imageFile = "images/{$imageName}.jpg"
header("Content-Type: image/jpeg");
header("Content-Length: " . filesize($imageFile));
readfile($imageFile);
exit;
}
// connect to the database
include "dbconn.php";
if(isset($_GET['image_id']) && is_numeric($_GET['image_id'])) {
$id = $_GET['image_id'];
// Since you store the type with the image, you may as
// well use it.
$sql = "SELECT content, type
FROM images
WHERE img_id={$id}";
$result = mysql_query($sql);
if ($result) {
$row = mysql_fetch_assoc($result);
header("Content-Type: " . $row["type"]);
header("Content-Length: " . strlen($row["content"]));
echo $row['content'];
exit;
}
else {
// Show an error image indicating SQL failure.
showError("sqlerror");
}
}
else{
// Show an error image indicating invalid input.
showError("inputerror");
}
Notice that this code fetches and uses the mime type stored with the image, instead of just using the JPEG content type. It also passes the Content-Length header, which is always a good idea when outputting binary data.
The while loop you used when processing the SQL results is also gone. You're only ever going to want to process a single row, so why use a loop?
And alwasy try to exit() the code after sending file data. You don't want to accidentally corrupt the image with some trailing spaces or something.