shadiadiph Posted December 30, 2008 Share Posted December 30, 2008 mm very tricky question I think. I have a edit images page but I am at a complete loss as to where to go from here any input would be appreciated the page that displays them calls them from another php page the images are stored in a database. I want to display a link edit delete under the images where an image is displayed. can i put anything on the editpic.php page here are the two codes I am running been sitting here thinking about this for hours can't think Any ideas?? html <table class="addpix"> <tr><td><img src="editpic1.php?adid=<?=$id?>" /></td> <td><img src="editpic2.php?adid=<?=$id?>" /></td> <td><img src="editpic3.php?adid=<?=$id?>" /></td> <td><img src="editpic4.php?adid=<?=$id?>" /></td></tr> </tr> </table> editpic1.php code <? session_start(); error_reporting(7); require("../global/admin_functions.php"); $sid = $_SESSION['LOGINID']; if($sid!="") { if (isset($_GET['adid'])) { $query = "SELECT thumbnail1,thumbnailtype1,description1 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_num_rows($result) ==1) { $data = mysql_result($result,0,"thumbnail1"); $type = mysql_result($result,0,"thumbnailtype1"); Header( "Content-type: $type"); print $data; } } header("Content-Type: image/png"); $file = ('../../pix/noimage.png'); $source = (fread(fopen($file, "r"), filesize($file))); print ($source); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/ Share on other sites More sharing options...
opalelement Posted December 30, 2008 Share Posted December 30, 2008 I'm not sure how to fix the problem you are asking about, but you definitely need to screen $_GET['adid'] before putting it in the query. Even if it isn't user input, I could make my own HTML file that calls <img src="http://whateversite.com/editpic1.php?adid=sqlInjectionHere" /> Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-725976 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 so it is probably safer to call the image directly from the database to the screen instead of using editpic1.php to call it correct that way anyone viewing the source wouldn't see it right. At the moment I am working on trying to embed the code of editpic1.php into the html but it isn't working getting the error i had alot while making the editpic1.php Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource. mm i went through hours trying to get that just to work oh well back to the drawing board. Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-725982 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 for example this script works fine on the seperate editpic.php but when i try to use it in the html page as <tr><td> <? $query = "SELECT thumbnail1,thumbnailtype1 FROM zloads where intProductID=$adid"; $result = mysql_query($query); if (mysql_num_rows($result) ==1) { $data = mysql_result($result,0,"thumbnail1"); $type = mysql_result($result,0,"thumbnailtype1"); Header( "Content-type: $type"); } ?> <img src="<?=$data?>" /> </td> keeps getting that sql-num_rows error??? Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-725988 Share on other sites More sharing options...
opalelement Posted December 30, 2008 Share Posted December 30, 2008 keeps getting that sql-num_rows error??? Copy the error here Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-725992 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 now it seems to have changed to Warning: Cannot modify header information - headers already sent by (output started at /home/hmtcompa/public_html/user/myaccount/updatepix.php:13) in /home/hmtcompa/public_html/user/myaccount/updatepix.php on line 152 ÿØÿàJFIFÿþ\‚ÛL³šöä.@A'• 3òç kä'pJúÎÖ^ç½4Ú²½š»wvÓ¹û¾3WçJ:9nùVîVºÚÞ÷kh¬|…g£ßÜ(2i³Ë…Â%‰\d[ ÜzÎ è,ü3 “ZÝA»îïŠBU€ÏðäìÏ X‚@èM|‹ð™õ¼?ñ£Å7?üSãjº¾±‰ZC™ÒoìÛ¨¢J_R£ì)GÚ?†Nœå)^9ye)L`ò¨á+äø§,½} //alot more of this// seems like it is almost reading it?? Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-725995 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 the first line of the gobbldigook in the html view source has same warning but also includes this. ÿØÿà JFIF ÿþ <CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 100 so it can see its a jpeg but isn't reading it properly ? Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-725999 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 been through the whole document and removed any other header comments but the error says the output was started by the one line diectly above print $data;???? <tr><td> <? $query = "SELECT thumbnail1,thumbnailtype1 FROM zloads where intProductID='$id'"; $result = mysql_query($query); if (mysql_num_rows($result) ==1) { $data = mysql_result($result,0,"thumbnail1"); $type = mysql_result($result,0,"thumbnailtype1"); header( "content-type: $type " ); print $data; } ?> </td> Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726031 Share on other sites More sharing options...
RussellReal Posted December 30, 2008 Share Posted December 30, 2008 you're having the problem because editpic.php must actually return an IMAGE firstly.. you cannot send a header after the output of the body.. secondly.. you can't generate an image mid page.. the<img> tag is meant to LINK to OTHER FILES Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726034 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 ok so I have moved the script to the top of the page and if i use print $data above the head it only shows the image on the page and none of the other html below it? if i put print $data; further down the page it writes rubbish like before the binary stuff how can i get around this? Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726039 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 i get you so this is totally impossible right? Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726040 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 I had an idea but it wont work the way I have laid it out because it is asking the if question before it has had a chance to get the data I am trying to display an image with delete edit if there is an image there $result="valid" and if there isn't an image display $result='invalid, but I know I have it all the wrong way round if anyone can help with this it would be appreciated or any ideas thanks. editpic2.php <? session_start(); error_reporting(7); require("../global/admin_functions.php"); $sid = $_SESSION['LOGINID']; if($sid!="") { if (isset($_GET['adid'])) { $query = "SELECT thumbnail2,thumbnailtype2 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_num_rows($result) ==1) { $data = mysql_result($result,0,"thumbnail2"); $type = mysql_result($result,0,"thumbnailtype2"); Header( "Content-type: $type" ); $result = "valid"; return $result; print $data; } } header("Content-Type: image/png"); $file = ('../../pix/noimage.png'); $source = (fread(fopen($file, "r"), filesize($file))); $result = "invalid"; return $result; print ($source); } ?> html <table class="addpix"> <? if ($_GET["result"]=="valid"){ ?> <td><img src="editpic1.php?adid=<?=$id?>" /><br /> EDIT DELETE</td> <? } if ($_GET["result"]=="invalid"){?> <td><img src="editpic1.php?adid=<?=$id?>" /></td> <? } ?> <? if ($_GET["result"]=="valid"){?> <td><img src="editpic2.php?adid=<?=$id?>" /><br /> EDIT DELETE</td> <? } ?> <? if ($_GET["result"]=="invalid"){?> <td><img src="editpic2.php?adid=<?=$id?>" /></td> <? } ?> please excuse my terrible coding Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726053 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 is it possible to use a staement like or similar to this one? <td><img src="editpic1.php?adid=<?=$id?><? $error = $_GET["error"]); ?>" /><br /> <? print $error; ?></td> Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726067 Share on other sites More sharing options...
RussellReal Posted December 30, 2008 Share Posted December 30, 2008 no dude.. it is SO impossible.. what the image generating script does is simply output an image.. outputting an image is outputting code if you output the html with the image the image gets messed up.. just leave it in the other file and do <img src="whatever.php"> Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726081 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 mm so everything seems so impossible right now no easy solutions to this i want to make it display edit delete where there is an image maybe i should look at other languages to use? Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726103 Share on other sites More sharing options...
shadiadiph Posted December 30, 2008 Author Share Posted December 30, 2008 would it be better to somehow create a temporary image from the image in the database first or would i just be going around in circles back to square one. I want to get the image from the database and where there is an image stored in the database make the display page also give an edit delete option this is very confusing I can't believe it is impossible as suggested?? Quote Link to comment https://forums.phpfreaks.com/topic/138837-solved-how-can-i-approach-this-loading-images-problem-from-the-database/#findComment-726141 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.