waynew Posted June 6, 2008 Share Posted June 6, 2008 Okay, firstly, I'm new to PHP. I have been at this for hours now and I really need to go to bed (It's 2.43am here). I'm trying to display all images that I've uploaded to a mysql database. My database table that holds the images is as follows: ID - INT(24) - AUTO INCREMENT TEXT - VARCHAR(400) IMAGE - LONGBLOB FILETYPE - VARCHAR(25) LINK - VARCHAR(100) DATE - DATE SITETITLE - VARCHAR(50) Now everything is working fine with the insertion. The problem is with the displaying. I have two files. These are only test files at the moment. But they're not working. displayform.php <?php session_start(); include("dbconnect.php"); $result = mysql_query("SELECT * FROM SEOLINKS ORDER BY DATE ASC"); mysql_close($conn); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Template</title> <link href="templatestyle.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style4 { color: #F29132; font-weight: bold; } --> </style> </head> <body> <!-- Start Div Container --><div id = "container"> <!-- Start Div Banner Holder --><div id = "bannerholder"> <!-- Start Div Banner --><div id ="banner"> <!-- End Div Banner --></div> <!-- End Div Banner Holder --></div> <div id = "navholder"><div id = "nav"> <dl> <dt><a href = "template.html" title = "Contact Roadway">Contact</a></dt> <dt><a href = "template.html" title = "Projects by Roadway">Projects</a> </dt> <dt><a href = "template.html" title = "Road Signs & Equipment">Products</a> </dt> <dt><a href = "template.html" title = "News">News</a> </dt> <dt><a href = "template.html" title = "All about Roadway">About Us</a></dt> <dt><a href = "template.html" title = "Buy road side signs and equipment | Ireland">Home</a> </dt> </dl></div></div> <!-- Start Div Nav Footer --> <!-- Start Div Content --> <div id = "content"> <div id = "formbox"> <?php while($row=mysql_fetch_array($result)) { echo "<img src=\"image.php?id=".$row['ID']."\">"; } ?> </div> <!-- End Div Content --></div> <!-- Start Div Footer --><div id = "footer"> <div id = "footerinfo">Example</div> <!-- End Div Footer --></div> <!-- End Div Container --></div> </body> </html> image.php <?php include("dbconnect.php"); $imgResult = mysql_query(sprintf("SELECT * FROM SEOLINKS WHERE ID = %s", $_GET['ID'])); $row = mysql_fetch_array($imgResult); header(sprintf("Content-type: %s", $row['FILETYPE'])); print($row['IMAGE']); ?> Any help on this would save me hours of sleep. Link to comment https://forums.phpfreaks.com/topic/108929-solved-in-dire-need-of-help-with-displaying-images-from-a-database/ Share on other sites More sharing options...
trq Posted June 6, 2008 Share Posted June 6, 2008 The first thing you need to do is check your queries succeed before attempting to use any results they may produce. As a quick debug you could simply catch any errors using die(). eg; $result = mysql_query("SELECT * FROM SEOLINKS ORDER BY DATE ASC") or die(mysql_error()); I believe using the name DATE as a field name will likely cause you grief. Link to comment https://forums.phpfreaks.com/topic/108929-solved-in-dire-need-of-help-with-displaying-images-from-a-database/#findComment-558853 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2008 Share Posted June 6, 2008 Define: "But they're not working." What is it doing? Do the <img tags in the html "view source" in the browser contain the expected content? What do you see? When you browse directly to image.php with a valid id parameter, what do you get? Link to comment https://forums.phpfreaks.com/topic/108929-solved-in-dire-need-of-help-with-displaying-images-from-a-database/#findComment-558855 Share on other sites More sharing options...
waynew Posted June 6, 2008 Author Share Posted June 6, 2008 Okay, I added some error checking to the SQL and it worked fine. Must be something else. Browse to the image.php file? Okay... I must be way out of my league on this one. I want to display all the pictures on the displayform.php page without having to browse anywhere? Is there a way of doing that? Oh and the images are turning up as images with the usual missing image box. Thanks for taking the time to help. Link to comment https://forums.phpfreaks.com/topic/108929-solved-in-dire-need-of-help-with-displaying-images-from-a-database/#findComment-558857 Share on other sites More sharing options...
Buddski Posted June 6, 2008 Share Posted June 6, 2008 Variables are case sensitive.. You are trying to call $_GET['ID'] on image.php Just call $_GET['id'] and see if it helps. Link to comment https://forums.phpfreaks.com/topic/108929-solved-in-dire-need-of-help-with-displaying-images-from-a-database/#findComment-558888 Share on other sites More sharing options...
waynew Posted June 6, 2008 Author Share Posted June 6, 2008 That was it. I changed it to $_GET['id'] and wallah, it worked. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/108929-solved-in-dire-need-of-help-with-displaying-images-from-a-database/#findComment-558997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.