Testing php, mysql, html and blobs

P

Paul

Hi,

I've created a very simple SQL database called images (really simple -
has 3 columns - id (primary key, smallint(6)), description
(varchar(127)) and image (longblob) for the image.

Using phpmyadmin, I've uploaded an image to the database and it's all
fine.

Next, created a webpage which calls a php script to render the file.
Only problem is that all that happens is the html is rendered and a few
seconds later, I get an error "The URL is not valid and cannot be
loaded".

The page looks like this

<html>
<head>
<title>Thumbnail tester</title>
</head>
<body bgcolor="#000">
<p style="text-align:center; font-size:2.0em; color:white">BE AFRAID</p>
<div align="center">
<img src="thumbnail.php?id=1" alt="A picture" />
</div>
</body>
</html>

The php is

<?php
$id=_POST['id'];
header("Content-type: image/jpeg");
$db = mysql_connect("localhost", "paul", "my_password_not_yours!");
mysql_select_db("testbase", $db);
$query = "select image from images where id=$id";
$result = mysql_query($query, $db);
$row = mysql_fetch_array($result);
$jpg = $row["image"];
echo $jpg;
?>

Any ideas where I'm going wrong?

TTFN

Paul

P.S. Yes, there is a good reason for me doing this and yes, I have done
the mandatory 35 minutes googling for an answer...
 
J

JDS

Next, created a webpage which calls a php script to render the file. Only
problem is that all that happens is the html is rendered and a few seconds
later, I get an error "The URL is not valid and cannot be loaded".

Some debugging hints:

1) change the header in thumbnail.php to
header("Content-type: text/plain");
Browse thumbnail.php dierctly:
In your browser, go to "http://your.server.butt/thumbnail.php"

Do you see any errors?

2) take out the reference to "thumbnail.php" in the original file. Does
the file load now?

I mean, remove the <img src="thumbnail.php?id=1" alt="A picture" /> line

3) You may want to rearrange the order of the lines in thumbnail.php.
Won't make too much of a difference, but put the header() line after all
the work is done and just before the "echo $jpg" line -- it just makes
more sense to me.

Also, put exit(); at the end of thumbnail.php. Sometimes that helps.
 
P

Paul

Hi,

Oh, and one last thing, this is alt.html. Try alt.php, alt.php.sql,
and/or comp.langphp for a better pool of PHP talent.

Limited news server at work :-(

TTFN

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top