calvinschools Posted May 8, 2011 Share Posted May 8, 2011 I have a gallery of pics when you click a pic you get sent to this page. Problem is I can't get the image to display. I know it's a GET function or img src="" but I can't get it right. This is my output. No styling yet. This is a template for all photos when clicked I want to drag the info of the pic selected and the comments that come along with it (not included yet) but could use some advice on that too. Thanks Name: gewqrgf photo: uploads/EmptyTwo.png state: wfe <!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>What do you know about.......</title> </head> <body> <?php $hostname='.'; $username='.'; $password='.!'; $dbname='.'; $usertable='.'; mysql_connect('.', ''', ''!') or die(mysql_error()); mysql_select_db("'") or die(mysql_error()); $result = mysql_query("SELECT * FROM photo") or die(mysql_error()); // store the record of the "example" table into $row $row = mysql_fetch_array( $result ); echo "Name: ".$row['name']; echo " photo: ".$row['photopath']; echo " state: ".$row['state']; ?> <?php //$photopath = mysql_real_escape_string($_REQUEST['photpath']); //$name = mysql_real_escape_string($_REQUEST['name']); //$state = mysql_real_escape_string($_REQUEST['state']); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/ Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 This page is for displaying a single picture, or the entire database? Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212136 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 just one. whichever one is selected from the gallery. I don't think my query is correct either. This is my first try at this so I'm not to sure of whats right and wrong. Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212137 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 Well, you have to change a few things to make this work right. Do you have an 'id' column (unique, auto_increment, primary) for your pictures? This is pretty much necessary. Once you have that, populate the links in your gallery with 'viewpicture.php?id=12345', where 12345 is the image's ID. Once you have that, you can easily select a single picture from your database to display it. <!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>What do you know about.......</title> </head> <body> <?php $hostname='.'; $username='.'; $password='.!'; $dbname='.'; $usertable='.'; mysql_connect('.', ''', ''!') or die(mysql_error()); mysql_select_db("'") or die(mysql_error()); if( is_numeric($_GET['id']) ) { $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = {$_GET['id']}"); or die(mysql_error()); // store the record of the "example" table into $row $row = mysql_fetch_array( $result ); echo "Name: ".$row['name']; echo " photo: ".$row['photopath']; echo " state: ".$row['state']; } else { echo 'BAD PHOTO ID'; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212142 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 each picture is uploaded by a user and each picture gets an id. Will this still work the same? Actually let me try it out. Also would this be the same way to deal with comments? Drop the comment system on the template page and just add another call for all comments associated with a pictures id? Tried it and keep getting BAD PHOTO ID. what do you mean "populate the links in your gallery with 'viewpicture.php?id=12345', where 12345 is the image's ID." Don't they already get assigned one when they are uploaded or is this something different? Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212146 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 That's the standard way of doing it. Simple and logical. Give it a try. If you run into issues, post them here! Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212150 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 I tried and nothing. BAD PHOTO ID Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212157 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 somethings up. Even when I put in a specific id I still get BAD PHOTO ID. Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212158 Share on other sites More sharing options...
fugix Posted May 8, 2011 Share Posted May 8, 2011 where is this bad photo id error coming from? Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212160 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 You'll get BAD PHOTO ID if $_GET['id'] isn't a number. I used that to prevent users from injecting SQL into your script. Made a mistake in my example as well } else { echo 'BAD PHOTO ID'; should be } else echo 'BAD PHOTO ID'; Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212162 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 whats up fugix? The bad photo id is coming everytime I click a photo on the gallery. And xyph the id is a number they start from 29 from testing but the ids are numbers. Should I create a new field of sorts? Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212163 Share on other sites More sharing options...
MadTechie Posted May 8, 2011 Share Posted May 8, 2011 here is a quick revise <?php $id = (int)$_GET['id']; if( $id > 0 ) { $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error()); // store the record of the "example" table into $row $row = mysql_fetch_array( $result ); echo "Name: ".$row['name']; echo " photo: ".$row['photopath']; echo " state: ".$row['state']; } else { echo 'BAD PHOTO ID'; } Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212164 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 The only way you should be getting a BAD ID error is if is_numeric( $_GET['id'] ) is false. You could try removing that check temporarily to see if it works... but I don't suggest putting it live without some form of sanitation EDIT - MadTechie's revision should work just as well. Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212165 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 even with techies revision still get bad id. I attached a screenshot of my db table just so you guys know I have an id field. I also just realized I have my images saving as a varchar. Might have to change that [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212170 Share on other sites More sharing options...
MadTechie Posted May 8, 2011 Share Posted May 8, 2011 Okay so we know the problem then, id isn't being passed via the URL (or its not a number) use the code below <?php $id = (int)$_GET['id']; if( $id > 0 ) { $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error()); // store the record of the "example" table into $row $row = mysql_fetch_array( $result ); echo "Name: ".$row['name']; echo " photo: ".$row['photopath']; echo " state: ".$row['state']; } else { echo 'BAD PHOTO ID'; echo "<BR />\n--------------------------------"; var_dump($_GET); echo "<BR />\n--------------------------------"; } and give us the results between the ----------------- if you get Array(0) then we're need to see the form its being posted from.. or the href of the link used either way you please confirm that the URL has the id Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212172 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 Ok here's the result: BAD PHOTO ID --------------------------------array(0) { } -------------------------------- and here's the href:<a href="image_show.php"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a> and this code is for the gallery where the photos are uploaded to then when clicked go to image_show page. Thanks for sticking around guys. <?php require_once('myconn.php'); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 40; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_myconn, $myconn); $query_Recordset1 = "SELECT `name`, `photopath`, `state` FROM photo"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; ?> <div id="photos"> <table border=""> <?php $i=0; $numperpage=8; ?> <?php do { ?> <?php if ($i%$numperpage==0) echo "<tr>"; ?> <td align="center"> <a href="image_show.php"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a> <br/> <?php echo $row_Recordset1['name']; ?><br/> <?php echo $row_Recordset1['state']; ?></td> <?php $i++; if ($i%$numperpage==0) echo "</tr>"; ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </div> </body> </html> <?php mysql_free_result($Recordset1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212178 Share on other sites More sharing options...
fugix Posted May 8, 2011 Share Posted May 8, 2011 whats up fugix? yoo whats up? Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212180 Share on other sites More sharing options...
MadTechie Posted May 8, 2011 Share Posted May 8, 2011 Yep, id wasn't sent Try this See updates //Added ID $query_Recordset1 = "SELECT `id`, `name`, `photopath`, `state` FROM photo"; //uPDATED <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a> full code <?php require_once('myconn.php'); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 40; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_myconn, $myconn); //Added ID $query_Recordset1 = "SELECT `id`, `name`, `photopath`, `state` FROM photo"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; ?> <div id="photos"> <table border=""> <?php $i=0; $numperpage=8; ?> <?php do { ?> <?php if ($i%$numperpage==0) echo "<tr>"; ?> <td align="center"> //uPDATED <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a> <br/> <?php echo $row_Recordset1['name']; ?><br/> <?php echo $row_Recordset1['state']; ?></td> <?php $i++; if ($i%$numperpage==0) echo "</tr>"; ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </div> </body> </html> <?php mysql_free_result($Recordset1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212181 Share on other sites More sharing options...
fugix Posted May 8, 2011 Share Posted May 8, 2011 are you storing your photos in a directory or only in your db Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212183 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 are you storing your photos in a directory or only in your db have them in a directory called uploads the saving the path in db. heres what I got Madtechie Name: iuhgu photo: uploads/Yourpartners state: asdfsg its coming through and the url is ok: /image_show.php?id=34 but the no image only the path Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212186 Share on other sites More sharing options...
MadTechie Posted May 8, 2011 Share Posted May 8, 2011 okay.. problem #1 sorted Now We need a little more details about the paths So can you give up the url of the html file and a url of the images for example http://localhost/image_show.php?id=34 http://localhost/uploads/myimage.jpg Now it seams the image filename is also missing so try changing <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a> to (the WHOLE line) <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src="/<?php echo $row_Recordset1['photopath'].$row_Recordset1['name'] ;?>" height="200" width="200"/></a> Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212189 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 So can you give up the url of the html file and a url of the images no problem. Yourpartnerspartners.com/photo_list.php Yourpartnerspartners.com/uploads/whatever.jpg Upload form: Yourpartnerspartners.com/upload_main.php (don't mind the styling) Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212190 Share on other sites More sharing options...
fugix Posted May 8, 2011 Share Posted May 8, 2011 yeah what exactly are you storing in your photopath field...this should be fairly easy Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212191 Share on other sites More sharing options...
MadTechie Posted May 8, 2011 Share Posted May 8, 2011 OKay the last update should show the image on the page with the link Now update the photo line in the file image_show.php to echo " photo: <img src=\"/{$row['photopath']}{$row['name']}\" height=\"200px\" width=\"200px\" />"; EDIT: i really don't see the point in this question yeah what exactly are you storing in your photopath field...this should be fairly easy Yeah fairly easy to guess! Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212193 Share on other sites More sharing options...
calvinschools Posted May 8, 2011 Author Share Posted May 8, 2011 yeah what exactly are you storing in your photopath field...this should be fairly easy the photopath field stores uploads/image.jpg, uploads/image2.png etc. I figured when called it would just go to the directory and grab the file. I don't like to store images on the db. Quote Link to comment https://forums.phpfreaks.com/topic/235810-problem-with/#findComment-1212194 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.