First of all: I'm only guessing. You say it doesn't work, but you didn't give us an error. To get that try typing the URL directly into your browser:
getdata.php3?id=5
(or whatever id you got)
I see .php3
You might want to consider an upgrade. If not, forget what I said about $_FILES and stuff because it won't work on php 3. It's OLD.
Okay, here's an exerpt of your script:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Store binary data into SQL Database</title></head>
<body>
<?php
if ($submit) {
// save image
} else {
// show form
}
?>
<?php
if($id) {
// get data
echo $data;
}
?>
</body>
</html>
I'll tell you where it'll go wrong:
If you echo an <img> tag, the browser tries to fetch the image with a new request.
It expects a header with a mime-type like this:
Content-type: image/jpeg\r\n
(or some other image type)
And then it expects a binary blob.
What it get's when it tries to download the image is this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Store binary data into SQL Database</title></head>
<body>
*COMPLETE FORM HERE CAUSE THERE'S NO $submit*
*BINARY BLOB*
You understand that is no image. That's HTML with some binary muck attached to it.
Maybe you should make a seperate script that doesn't output anything (not even a newline) exept for the header and the image.
like:
show_image.php
<?php
if($id) {
// you may have to modify login information for your database server:
$query = "select bin_data,filetype from binary_data where id=$id";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0,"bin_data");
$type = @MYSQL_RESULT($result,0,"filetype");
Header( "Content-type: $type");
echo $data;
}
?>