mcirl2 Posted February 26, 2008 Share Posted February 26, 2008 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 Link to comment https://forums.phpfreaks.com/topic/93103-problems-dynamically-loading-images-from-mysql/ Share on other sites More sharing options...
amites Posted February 26, 2008 Share Posted February 26, 2008 my suggestion: get those images out of the database and place them on the server somewhere, then put pointers to the images in your database, make sense? Link to comment https://forums.phpfreaks.com/topic/93103-problems-dynamically-loading-images-from-mysql/#findComment-477201 Share on other sites More sharing options...
mcirl2 Posted February 28, 2008 Author Share Posted February 28, 2008 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?? Link to comment https://forums.phpfreaks.com/topic/93103-problems-dynamically-loading-images-from-mysql/#findComment-479030 Share on other sites More sharing options...
dave420 Posted February 28, 2008 Share Posted February 28, 2008 I'd recommend you store them in the filesystem - that's what it's there for Make your script create the necessary directories as needed, and do it that way. Link to comment https://forums.phpfreaks.com/topic/93103-problems-dynamically-loading-images-from-mysql/#findComment-479034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.