big-dog1965 Posted May 22, 2009 Share Posted May 22, 2009 I’m echoing results to a page I have a form that inserts data to mysql $query = "INSERT into `".$db_table."` (venue,address,date_1,time_1,date_2,time_2,date_3,time_3,date_4,time_4,host,host_email,venue_website,venue_phone,logo_image) VALUES ('" . $_POST['venue'] . "','" . $_POST['address'] . "','" . $_POST['date_1'] . "','" . $_POST['time_1'] . "','" . $_POST['date_2'] . "','" . $_POST['time_2'] . "','" . $_POST['date_3'] . "','" . $_POST['time_3'] . "','" . $_POST['date_4'] . "','" . $_POST['time_4'] . "','" . $_POST['host'] . "','" . $_POST['host_email'] . "','" . $_POST['venue_website'] . "','" . $_POST['venue_phone'] . "','" . $_POST['logo_image'] . "')"; mysql_query($query); mysql_close($link); //This sends an email with results from form summated. Which gives a link to image when clicked it shows the image. mail("admin@email.com","Venue Form submissions","Venue data: Venue: " . $_POST['venue'] . " Address: " . $_POST['address'] . " Date1: " . $_POST['date_1'] . " Time1: " . $_POST['time_1'] . " Date2: " . $_POST['date_2'] . " Time2: " . $_POST['time_2'] . " Date3: " . $_POST['date_3'] . " Time3: " . $_POST['time_3'] . " Date4: " . $_POST['date_4'] . " Time4: " . $_POST['time_4'] . " Host: " . $_POST['host'] . " Host Email: " . $_POST['host_email'] . " Venues Website: " . $_POST['venue_website'] . " Venues Phone: " . $_POST['venue_phone'] . " Venues Logo: ".$where_form_is."files/".$logo_image_filename." (original file name: " . $_FILES['logo_image']['name'] . ") "); But if I look at the database table field logo_imagae it is empty. This echo’s the results of submitted page. $query= 'SELECT venue, address, date_1, time_1, date_2, time_2, date_3, time_3, date_4, time_4, host, host_email, venue_website, venue_phone, logo_image FROM Venues ORDER BY date_1 ASC LIMIT 0, 100'; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { if (!empty($row['venue'])) echo "<b>".$row['venue']."</b><br />\n"; if (!empty($row['address'])) echo $row['address']."<br />\n"; if (!empty($row['date_1'])) echo $row['date_1']." "; if (!empty($row['time_1'])) echo $row['time_1']."<br />\n"; if (!empty($row['date_2'])) echo $row['date_2']." "; if (!empty($row['time_2'])) echo $row['time_2']."<br />\n"; if (!empty($row['date_3'])) echo $row['date_3']." "; if (!empty($row['time_3'])) echo $row['time_3']."<br />\n"; if (!empty($row['date_4'])) echo $row['date_4']." "; if (!empty($row['time_4'])) echo $row['time_4']."<br />\n"; if (!empty($row['host'])) echo "Host: ".$row['host']." "; if (!empty($row['host_email'])) echo "Host Email: ".$row['host_email']."<br />\n"; if (!empty($row['venue_website'])) echo $row['venue_website']."<br />\n"; if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; if (!empty($row['logo_image'])) echo $row['logo_image']."<br />\n"; //tried this to echo image but displays X image echo "<img src='/venue/files/' ".$row['logo_image']." '>"; echo "<hr>"; } No image from logo_image is displayed. the image is stored in a directory I tried the part at // and it gives me a X image but the actual image isn’t displayed I believe because the field is empty and doesn’t know what to get to display. So how do I insert the file name into the logo_image field and what do I do to echo the image on the page. Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/ Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 change echo "<img src='/venue/files/' ".$row['logo_image']." '>"; to echo "<img src='/venue/files/".$row['logo_image']."'>"; that will display an image if their is one, but if theirs no image your need a default image ie $noImage = "MyNoImageImage.jpg"; $img = (empty($row['logo_image']))?$noImage:$row['logo_image']; echo "<img src='/venue/files/$img'>"; Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840271 Share on other sites More sharing options...
Brian W Posted May 22, 2009 Share Posted May 22, 2009 is that all your code? you should use mysql_error() after your queries... example: mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840272 Share on other sites More sharing options...
big-dog1965 Posted May 22, 2009 Author Share Posted May 22, 2009 Still doesnt display image Just X for image also the noimage displays X for no image I dont understand how it would know which image, if the database doesnt have anything in the logo_image field Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840301 Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 Erm.. can you view source and tell me what the image scr is, my code should work but your also need a default image ie MyNoImageImage.jpg Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840310 Share on other sites More sharing options...
big-dog1965 Posted May 22, 2009 Author Share Posted May 22, 2009 http://www.mysite.com/starsite/venue/files/ http://www.mysite.com/starsite/venue/files/parachute_01.jpg change noimage to one in folder to see if worked I will make a noimage after it works and yes there are images in directory echo "<img src='admin/venue/files/".$row['logo_image']."'>"; $noImage = "parachute_01.jpg"; $img = (empty($row['logo_image']))?$noImage:$row['logo_image']; echo "<img src='admin/venue/files/$img'>"; Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840324 Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 your going to need to remove this line echo "<img src='admin/venue/files/".$row['logo_image']."'>"; Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840325 Share on other sites More sharing options...
big-dog1965 Posted May 22, 2009 Author Share Posted May 22, 2009 Still didnt work here what the page displays EyeRock Night Club 123 Some Address 05/23/2009 9:ooPm to 2:00Am 05/30/2009 8:ooPm to 1:00Am 06/06/2009 7:ooPm to 12:00Am 06/20/2009 9:ooPm to 2:00Am Host: Wild Bill Host Email: WildBill@dong.ding www.EyeRock.net 316-838-2222 HERES WHERE THE X image is showing up. $query= 'SELECT venue, address, date_1, time_1, date_2, time_2, date_3, time_3, date_4, time_4, host, host_email, venue_website, venue_phone, logo_image FROM Venues ORDER BY date_1 ASC LIMIT 0, 100'; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { if (!empty($row['venue'])) echo "<b>".$row['venue']."</b><br />\n"; if (!empty($row['address'])) echo $row['address']."<br />\n"; if (!empty($row['date_1'])) echo $row['date_1']." "; if (!empty($row['time_1'])) echo $row['time_1']."<br />\n"; if (!empty($row['date_2'])) echo $row['date_2']." "; if (!empty($row['time_2'])) echo $row['time_2']."<br />\n"; if (!empty($row['date_3'])) echo $row['date_3']." "; if (!empty($row['time_3'])) echo $row['time_3']."<br />\n"; if (!empty($row['date_4'])) echo $row['date_4']." "; if (!empty($row['time_4'])) echo $row['time_4']."<br />\n"; if (!empty($row['host'])) echo "Host: ".$row['host']." "; if (!empty($row['host_email'])) echo "Host Email: ".$row['host_email']."<br />\n"; if (!empty($row['venue_website'])) echo $row['venue_website']."<br />\n"; if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; if (!empty($row['logo_image'])) echo $row['logo_image']."<br />\n"; $noImage = "parachute_01.jpg"; $img = (empty($row['logo_image']))?$noImage:$row['logo_image']; echo "<img src='admin/venue/files/$img'>"; Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840327 Share on other sites More sharing options...
big-dog1965 Posted May 22, 2009 Author Share Posted May 22, 2009 to my above post I tried this as well if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; echo "<img src='/venue/files/".$row['logo_image']."'>"; $noImage = "MyNoImageImage.jpg"; $img = (empty($row['logo_image']))?$noImage:$row['logo_image']; echo "<img src='admin/venue/files/$img'>"; Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840334 Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 view source and paste the outputted html that displays has the image link Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840335 Share on other sites More sharing options...
big-dog1965 Posted May 22, 2009 Author Share Posted May 22, 2009 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Venues</title> <script src="css_js/nav.js"></script> <script type="text/javascript" src="css_js/ajaxcontent.js"> </script> <body class="body"> <div id="header" align="center"> <script>document.write(header());</script> </div> </head> <body class="body"> <div align="center"> <table border="0" width="500px" cellspacing="1"> <tr> <td> <b>Papas Bar & Grill</b><br /> 123 elm<br /> <img src='/venue/files/'><img src='admin/venue/files/MyNoImageImage.jpg'><hr><b>EyeRock Night Club</b><br /> 123 Some Address<br /> 05/23/2009 9:ooPm to 2:00Am<br /> 05/30/2009 8:ooPm to 1:00Am<br /> 06/06/2009 7:ooPm to 12:00Am<br /> 06/20/2009 9:ooPm to 2:00Am<br /> Host: Wild Bill Host Email: WildBill@dong.ding<br /> www.EyeRock.net<br /> 316-838-2222<br /> <img src='/venue/files/'><img src='admin/venue/files/MyNoImageImage.jpg'><hr> </td> </tr> </table> </div> <div style="position: absolute; width: 160px; left: 20px; top: 110px" id="topleft"><script>document.write(menu());</script> </div> <div style="position: absolute; width: 230px; right: 5px; top: 110px" id="topright"> </div> <script type="text/javascript"> ajaxpage('admin/venues/venuespg.php','topright') //load "test.htm" into "lefttop" DIV </script> <p align="center"> <IMG src="images/musicstaff.gif" width="480" height="25"><BR> <FONT face="Arial, Helvetica, sans-serif" size=1> </p> <div id="menu2" align="center"> <script>document.write(menu2());</script> </div> </FONT> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840342 Share on other sites More sharing options...
MadTechie Posted May 23, 2009 Share Posted May 23, 2009 <img src='/venue/files/'><img src='admin/venue/files/MyNoImageImage.jpg' as i said you need to remove echo "<img src='/venue/files/".$row['logo_image']."'>"; and does this MyNoImageImage.jpgimage exist in this admin/venue/files/ path ? Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840349 Share on other sites More sharing options...
big-dog1965 Posted May 23, 2009 Author Share Posted May 23, 2009 oK noimage.jpg shows now " I had it misspelled", but I used the form to upload image so it should show, I would think but again I dont understand how if in the DB the logo_image field is blank. So now what to do? $query = "INSERT into `".$db_table."` (venue,address,date_1,time_1,date_2,time_2,date_3,time_3,date_4,time_4,host,host_email,venue_website,venue_phone,logo_image) VALUES ('" . $_POST['venue'] . "','" . $_POST['address'] . "','" . $_POST['date_1'] . "','" . $_POST['time_1'] . "','" . $_POST['date_2'] . "','" . $_POST['time_2'] . "','" . $_POST['date_3'] . "','" . $_POST['time_3'] . "','" . $_POST['date_4'] . "','" . $_POST['time_4'] . "','" . $_POST['host'] . "','" . $_POST['host_email'] . "','" . $_POST['venue_website'] . "','" . $_POST['venue_phone'] . "','" . $_POST['logo_image'] . "')"; mysql_query($query); mysql_close($link); Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840360 Share on other sites More sharing options...
MadTechie Posted May 23, 2009 Share Posted May 23, 2009 in the field is blank AKA empty, then that where this line is usful $img = (empty($row['logo_image']))?$noImage:$row['logo_image']; its a shorthand version of this if(empty($row['logo_image'])) { $img = $noImage; }else{ $img = $row['logo_image']; } so if the $row['logo_image'] is empty then $img = $noImage; otherwise $img = $row['logo_image']; Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840370 Share on other sites More sharing options...
big-dog1965 Posted May 23, 2009 Author Share Posted May 23, 2009 So where do I put that code and should I use the short hand or other Beings Im a very noob maybe the long so I can edit and stuff in future if need be Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840383 Share on other sites More sharing options...
MadTechie Posted May 23, 2009 Share Posted May 23, 2009 yeah use the long one.. okay heres some new code, if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; if(empty($row['logo_image']) && true) //debug { echo "<img src='admin/venue/files/MyNoImageImage.jpg'>"; // no image }else{ echo "<img src='admin/venue/files/{$row['logo_image']}'>"; found image } first update echo "<img src='admin/venue/files/MyNoImageImage.jpg'>"; // no image so it displays an image (during the first test this will always display) once that displays remove "&& true" if(empty($row['logo_image']) && true) //debug and make sure the path on the line below is correct then test again Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840405 Share on other sites More sharing options...
big-dog1965 Posted May 23, 2009 Author Share Posted May 23, 2009 I tried it with the && true and without it got the same results both ways the noimage showed, but not the one uploaded thru form. Heres what the mysql DB looks like field names and data venue | address | date_1 | time_1 | date_2 | time_2 | date_3 | time_3 | date_4 | time_4 | host | host_email | venue_website | venue_phone | logo_image EyeRock Night Club 123 Some Address 05/23/2009 9:ooPm to 2:00Am 05/30/2009 8:ooPm to 1:00Am 06/06/2009 7:ooPm to 12:00Am 06/20/2009 9:ooPm to 2:00Am Wild Bill WildBill@dong.ding www.EyeRock.net 316-838-2222 Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840469 Share on other sites More sharing options...
MadTechie Posted May 23, 2009 Share Posted May 23, 2009 The && TRUE makes sure it used the MyNoImageImage.jpg, now thats showing you remove the && TRUE as you said you aree getting the same results thats to be expected as the data you posted has no image! Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840611 Share on other sites More sharing options...
big-dog1965 Posted May 23, 2009 Author Share Posted May 23, 2009 I got the noimage.jpg but not the image that goes with the data from DB Sorry bad grammer Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840693 Share on other sites More sharing options...
big-dog1965 Posted May 24, 2009 Author Share Posted May 24, 2009 I tried this if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; while ( $row = mysql_fetch_array ($logo_image) ) { $logo_image = $row["logo_image"]; //picname is the name of the field in the images table } if(empty($row['logo_image']) && true) //debug { echo "<img src='admin/venues/files/noimage.gif'>"; // no image }else{ echo "<img src='admin/venues/files/{$row['logo_image']}'>"; // found image } echo "<hr>"; } Got this error but it shows the noimage image Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /public_html/venues.php on line 61 line 61 is while ( $row = mysql_fetch_array ($logo_image) ) Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-840991 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 Okay well that code will never work.. if you keep changing random parts this will never get resolved! your code should look like this $query= 'SELECT venue, address, date_1, time_1, date_2, time_2, date_3, time_3, date_4, time_4, host, host_email, venue_website, venue_phone, logo_image FROM Venues ORDER BY date_1 ASC LIMIT 0, 100'; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { if (!empty($row['venue'])) echo "<b>".$row['venue']."</b><br />\n"; if (!empty($row['address'])) echo $row['address']."<br />\n"; if (!empty($row['date_1'])) echo $row['date_1']." "; if (!empty($row['time_1'])) echo $row['time_1']."<br />\n"; if (!empty($row['date_2'])) echo $row['date_2']." "; if (!empty($row['time_2'])) echo $row['time_2']."<br />\n"; if (!empty($row['date_3'])) echo $row['date_3']." "; if (!empty($row['time_3'])) echo $row['time_3']."<br />\n"; if (!empty($row['date_4'])) echo $row['date_4']." "; if (!empty($row['time_4'])) echo $row['time_4']."<br />\n"; if (!empty($row['host'])) echo "Host: ".$row['host']." "; if (!empty($row['host_email'])) echo "Host Email: ".$row['host_email']."<br />\n"; if (!empty($row['venue_website'])) echo $row['venue_website']."<br />\n"; if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; if (!empty($row['logo_image'])) echo $row['logo_image']."<br />\n"; //tried this to echo image but displays X image if(empty($row['logo_image'])) //debug { echo "<img src='admin/venues/files/noimage.gif'>"; // no image }else{ echo "<img src='admin/venues/files/{$row['logo_image']}'>"; // found image } echo "<img src='/venue/files/' ".$row['logo_image']." '>"; echo "<hr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-841144 Share on other sites More sharing options...
big-dog1965 Posted May 24, 2009 Author Share Posted May 24, 2009 Ok I went back to that version and copied yhe code you have there, but now it kills the rest of my page and still only display an X for the imag. also now it puts an X for new record data too. Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-841171 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 Sighs! okay well the fix is if(empty($row['logo_image'])) { echo "<img src='admin/venues/files/noimage.gif'>"; // no image }else{ echo "<img src='admin/venues/files/{$row['logo_image']}'>"; // found image } thats how you display the image a default image if the value in the database is empty the red cross means it can't find the image, (double check the path and the image name) Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-841173 Share on other sites More sharing options...
big-dog1965 Posted May 24, 2009 Author Share Posted May 24, 2009 Im sorry this is taking so long Im frustrated.. I changed to what you have in the last post deleted all past form data and images in the files folder and made 1 new entry with a small image. I get the noimage pic to show but not the one I uploaded. checked the files dir and it is there. Its like it doesnt see anything in the logo_image field to go get. the field is blank if I look at the sql table, so it leads me to believe I got something wrong in the process of the form. ??? Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-841175 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 thats correct, if the database's field is empty then the image can't be found (it doesn't know its name), thus a default image is showed in its place, check the upload code, (or post it) Quote Link to comment https://forums.phpfreaks.com/topic/159319-solved-form-inserting-to-mysql-then-echoing-a-image-from-the-database-to-a-webpage/#findComment-841185 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.