PdVortex Posted January 21, 2008 Share Posted January 21, 2008 Hello wondering if anyone can help me with this problem i got. The script below should grab a picture from the database depending on what a person has input into a form. All i get is a blank page with nothing on it Can anyone help me out i been puzzling away at this for hours now. Thanks for any help in advance. $password = "*****"; $hostname = "*********"; $database = "*************"; $username = "***********"; $conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); mysql_select_db($database, $conn) or die("Selecting MySQL database failed"); $location = $_POST['location']; $destination = $_POST['destination']; $img = mysql_query("SELECT img FROM routes WHERE location='$location' AND destination='$destination'"); if (!$img) { die('Could not query:' . mysql_error()); } echo mysql_result($img, 0); Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/ Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 Try using complete syntax in your mysql statement. If that doesn't fix it take a look at the php error log. $img = mysql_query("SELECT `img` FROM `routes` WHERE `location` = '$location' AND `destination` = '$destination'"); Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445451 Share on other sites More sharing options...
marcus Posted January 21, 2008 Share Posted January 21, 2008 p2grace, his syntax is fine. do something like: <?php $img = mysql_query("SELECT `img` FROM `routes` WHERE `location` = '".mysql_real_escape_string($location)."' AND `destination` = '".mysql_real_escape_string($destination)."'") or die(mysql_error()); if(mysql_num_rows($img) > 0){ $row = mysql_fetch_assoc($img); echo $row['img']; }else { echo "Doesn't exist"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445461 Share on other sites More sharing options...
PdVortex Posted January 21, 2008 Author Share Posted January 21, 2008 Thanks for the response i have tryed the full code but no luck . . . also i have looked in the error log and there is nothing in there Any other suggestions? Does my code look ok? i am fairly new to all this. Thanks again for any help in advance. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445474 Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 Try taking the query and testing it in phpmyadmin. See what kind of errors phpmyadmin finds. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445478 Share on other sites More sharing options...
PdVortex Posted January 21, 2008 Author Share Posted January 21, 2008 Ok i tried mgallforever suggest but it still just shows a blank screen. But Thanks So i went to phpmyadmin and typed this : SELECT img FROM routes WHERE location AND destination And its response was : MySQL returned an empty result set (i.e. zero rows). (Query took 0.0002 sec) Was that what you ment? Once again thanks for any help in advance. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445489 Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 Your query needs to specify where location equals something and destination equals something SELECT `img` FROM `routes` WHERE `location` = 'something' AND `destination` = 'something' Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445491 Share on other sites More sharing options...
PdVortex Posted January 21, 2008 Author Share Posted January 21, 2008 OK cool done that : SELECT `img` FROM `routes` WHERE `location` = 'New York' AND `destination` = 'Omicron Alpha' Returned with : Showing rows 0 - 0 (1 total, Query took 0.0354 sec) So it works on there. So must be something with my code? ? Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445504 Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 Are you sure that your post variables are correct? I'd echo them and make sure they're identical to what's in the database. Also adding trim() to your post variables is a good idea to remove any extra spaces that might throw off the query. I always make sure I trim() and mysql_real_escape_string() all variables before they going into an sql statement. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445510 Share on other sites More sharing options...
rhodesa Posted January 21, 2008 Share Posted January 21, 2008 OK cool done that : SELECT `img` FROM `routes` WHERE `location` = 'New York' AND `destination` = 'Omicron Alpha' Returned with : Showing rows 0 - 0 (1 total, Query took 0.0354 sec) So it works on there. So must be something with my code? ? No, your query isn't returning any rows, so nothing will be shown. Are there any rows in your table? If so, what are the values of location/destination for them? Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445513 Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 We've already established there are rows in the table because when he entered the query straight into phpmyadmin it worked. I'm testing the location/destination variables because they're not returning anything in the query. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445514 Share on other sites More sharing options...
PdVortex Posted January 21, 2008 Author Share Posted January 21, 2008 Ok this is the form im using. <form id="form1" name="form1" method="POST" action="search/new-search.php"> <div align="center"><span class="style1">Current Location</span> <input type="text" name="Current Location" id="location" /> </div> <div align="center"><span class="style1">Disierd Destination </span> <input type="text" name="Destination" id="destination" /> </div> <div align="center"></div> <div align="center"> <input type="submit" name="submit" id="submit" value="Submit" /> </div> <div align="center"></div> </form> <p align="center" class="style1"> </p> </body> </html> As for the trim things im sorry but can show me how because you lost me at trim() Thanks again for any help. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445531 Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 There's your problem, your post variables aren't named correctly. Change the form to this: <form id="form1" name="form1" method="POST" action="search/new-search.php"> <div align="center"><span class="style1">Current Location</span> <input type="text" name="location" id="location" /> </div> <div align="center"><span class="style1">Desired Destination </span> <input type="text" name="destination" id="destination" /> </div> <div align="center"></div> <div align="center"> <input type="submit" name="submit" id="submit" value="Submit" /> </div> <div align="center"></div> </form> <p align="center" class="style1"> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445533 Share on other sites More sharing options...
PdVortex Posted January 21, 2008 Author Share Posted January 21, 2008 OMG Im such a spastic. I always look at the harder things and overlook the easy bits. Thanks for you help and sorry for wasting you time. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445540 Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 No problem, glad I could help Would you mind marking hitting the "Topic Solved" button Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445543 Share on other sites More sharing options...
PdVortex Posted January 21, 2008 Author Share Posted January 21, 2008 Oh ok so i got it calling from the Databas enow but its only showing the link not the actual picture Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445545 Share on other sites More sharing options...
p2grace Posted January 21, 2008 Share Posted January 21, 2008 What's in the database? Is it a path to the image? If it is you need to add the img tags to the echo statement. echo "<img src=\"".$row['img']."\" alt=\"alt text\" /><br />"; Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445550 Share on other sites More sharing options...
PdVortex Posted January 21, 2008 Author Share Posted January 21, 2008 Super thanks very much. Quote Link to comment https://forums.phpfreaks.com/topic/87100-solved-displaying-a-picture-which-is-being-pulled-from-mysql/#findComment-445643 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.