Jump to content

Problems Dynamically loading images from mysql


mcirl2

Recommended Posts

Hi,

 

I have a simple php script which will retrieve images from the table based on the query. The problem is that when I hard code a value to the $id variable that I use in the select statement, the image is dislayed no problem. However as soon as I use the $_GET['id'] variable in the query it wont work. It prints out other text values for the row, but not the iimage.

 

Here's my code:

 

<?php



// Connect to database




$errmsg = "";
if (! @mysql_connect("localhost","root","******")) {
        $errmsg = "Cannot connect to database";
        }
@mysql_select_db("*****");




$id = $_GET['id'];
//$id = 31;
//when I uncomment the above variable the query will pull out all the values where AdvID = 31
//but when I use the Get ID .. it wont work. The value of $_GET['id'] is 31 also. 

$slqQ = @mysql_query("select * from advpics where AdvID = $id");
if ($row = @mysql_fetch_assoc($slqQ)) 
{
        $title = htmlspecialchars($row[title]);
        $bytes = $row[imgdata];
$desc = $row ['AdvID'];
} 



//If this is the image request, send out the image

if ($_REQUEST[gim] == 1) 
{
        
header("Content-type: image/jpeg");
        print $bytes;
        exit ();
       }
?>

<html><head>
<title>Upload an image to a database</title>
<body bgcolor=white><h2 align="center">Here's the latest picture</h2>
<font color=red><?= $errmsg ?></font>


<center><img src=?gim=1 width=144><br>
<p align="center"><?= $title ?></p>
<p><?= $desc;  ?></p>
</center>

</body>
</html>

 

 

 

I would really appreciate some help, cant figure it out at all.

 

Thanks,

 

Mike

hey,

 

the problem is that I need to store the images in  the database because users can create profiles and so they would have to create a seperate directory every time they create a profile so its easier to store int he database.

 

I wish I didnt have too, its a nightmare!!

 

Any other ideas - anyone??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.