calvinschools Posted May 9, 2011 Share Posted May 9, 2011 Ok. Thought I'd be able to do this myself but ran into a couple of snags. This is the template page for the image thumbnails. WHen a thumbnail is clicked it is dragged into this template. I put the code for the comments on the page but it's just not working properly. When I post comment the comment posts but the picture turns into my BAD PHOTO ID error message. Have some ideas on whats going but it's getting kind of messy. If you need to see the pages from the comment system I will post. Thanks phpeople. Where's fugix? <!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> <style type="text/css"> #What { text-align: center; } </style> </head> <body> <div id="What"><img src="images/what.png" width="477" height="36" alt="do you know something i don't" /></div> <?php $hostname='fd.db.fdffd.d.com'; $username='d'; $password='d!'; $dbname='d'; $usertable='d'; mysql_connect('yd.com', 'yd9', 'Ad!') or die(mysql_error()); mysql_select_db("yd9") or die(mysql_error()); $id = (int)$_GET['id']; if( $id > 0 ) { $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br /> "; echo $row['name']. "\n". "<br/>"; echo $row['state']. "\n"; } else { echo 'BAD PHOTO ID'; } ?> <?php $hostname='durce.com'; $username='yod9'; $password='Ad1!'; $dbname='yd'; $usertable='d'; mysql_connect('yd, 'yd9', 'Ad!') or die(mysql_error()); mysql_select_db("yd") or die(mysql_error()); $name=$_POST['name']; $comment=$_POST['comment']; $submit=$_POST['submit']; if($submit) { if($name&&$comment) { $query=mysql_query("INSERT INTO comment (id,name,comment) VALUES ('','$name','$comment')"); } else { echo "Please fill out all the fields."; } } ?> <body> <div id="comments"> <form action="image_show.php" method="POST"> <label>Name: </label><br /><input type="text" name="name" input id="name"value="<?php echo "$name" ?>" /><br /><br /> <label>Comment: </label><br /><input type="text" input id="comment"/><textarea name="comment" "cols="25" rows="7"></textarea><br /><br /><br /> <input type="submit" name="submit" value="Comment" /><br /> </form></div> <hr width="1100px" size="5px" /> </body> <?php $query=mysql_query("SELECT * FROM comment ORDER BY id DESC"); while($rows=mysql_fetch_assoc($query)) { $id=$rows['id']; $name=$rows['name']; $comment=$rows['comment']; $linkdel="<a href=\"delete.php?id=" . $rows['id'] . "\">Delete User</a>"; echo '<font color="red">Name:</font> ' . $name . '<br />' . '<br />' . '<font color="red">Comments:</font> ' . '<br />' . $comment . ' ' . ' ' . ' ' . ' ' . $linkdel . '<br />' . '<br />' . '<hr size="5px" width="500px" color="blue" />' ; } ?> </html> </body> </html> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 looks like you are receiving this error because $id = (int)$_GET['id']; is not returning anything. Where is the $_GET['id']; coming from? Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 that id is the id of the thumbnail thats clicked. It drags all the info into the template. That all works fine but once I put the comment system in I'm getting Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/20/7812420/html/comment.php on line 33. ANd if I do post a comment the photo disappears with a BAD PHOTO ID error message. This is a comment system I wrote to stand alone so would it be easier to re-write one into the page. The comment page also uses success.php connect.php and delete.php Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 whats up fugix? told you I'd be back. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 well your bad photoid error comes from this $id = (int)$_GET['id']; if( $id > 0 ) { $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br /> "; echo $row['name']. "\n". "<br/>"; echo $row['state']. "\n"; } else { echo 'BAD PHOTO ID'; } so what i would do is echo the id before running the if statement to see if i am returning anything $id = (int)$_GET['id']; echo $id; if( $id > 0 ) { $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br /> "; echo $row['name']. "\n". "<br/>"; echo $row['state']. "\n"; } else { echo 'BAD PHOTO ID'; } Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 the bad photo error only comes when you submit a comment and the page reloads. prior to that the photo is there. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 i think that you are receiving that error because your form action is not dynamic...meaning that it is not sending an id to itself...so when this $id = (int)$_GET['id']; tries to retrieve an id...it doesn't receive one, and you get your error, you need to make your form send an id like this <form action="image_show.php?id=1" method="POST"> and you would replace the one with whatever the id is supposed to be Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 alright i think i see whats going on. The comments are posting they are being pulled from db when thumbnail is clicked but photo still disappears when posting a comment. The url goes from having an id say 48 before posting to going to id=$id after with no pic. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 well insert the proper id into the form action like i said and you should be good Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 there is no proper id. It's whatever photo the user clicks. It's not my own gallery it's uploaded photos from users that go into a main page then when clicked enter the template. And whats happening is when the page is run again to publish the comment the pic disappears. Not when first called. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 well if you arent passing an id through your form then what is the purpose of $id = (int)$_GET['id']; then? Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 that gets the id of the picture selected. When you go to the gallery and click a photo the photo opens in the template comments below it, url displaying id then when you publish a comment and the page refreshes then the pic disappears and id goes to id=$id and even img src has no path for the image. before comment: <img src="/uploads/photo_12.png" height="400px" width="400px" /><br /> after comment: BAD PHOTO ID <img src="/" height="400px" width="400px" /><br /> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 and from where in your code is the $id = (int)$_GET['id']; coming from? this line $id = (int)$_GET['id']; is causing all of your problems, if we can just get this sorted out you'll be good Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 sorry I was getting confused. That id is coming from this page where all the photos are uploaded to. <!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>The List</title> <style type="text/css"> #a { text-decoration: none; } </style> </head> <body> <div id="header"></div> <?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 ORDER BY `name` ASC"; $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="1" bordercolor="#000000"> <?php $i=0; $numperpage=10; ?> <?php do { ?> <?php if ($i%$numperpage==0) echo "<tr>"; ?> <td align="center"> <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src='<?php echo $row_Recordset1['photopath'] ;?>' height="100" width="100"/></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); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 okay so let me get organized here when you click this link <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src='<?php echo $row_Recordset1['photopath'] ;?>' height="100" width="100"/></a> everything works as it should....the picture shows and everything, however when someone writes and comment and hits the submit button...the image does not show anymore? Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 right. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 okay so you're going to try this <!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> <style type="text/css"> #What { text-align: center; } </style> </head> <body> <div id="What"><img src="images/what.png" width="477" height="36" alt="do you know something i don't" /></div> <?php $hostname='fd.db.fdffd.d.com'; $username='d'; $password='d!'; $dbname='d'; $usertable='d'; mysql_connect('yd.com', 'yd9', 'Ad!') or die(mysql_error()); mysql_select_db("yd9") or die(mysql_error()); $id = (int)$_GET['id']; if( $id > 0 ) { $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br /> "; echo $row['name']. "\n". "<br/>"; echo $row['state']. "\n"; } else { echo 'BAD PHOTO ID'; } ?> <?php $hostname='durce.com'; $username='yod9'; $password='Ad1!'; $dbname='yd'; $usertable='d'; mysql_connect('yd, 'yd9', 'Ad!') or die(mysql_error()); mysql_select_db("yd") or die(mysql_error()); $name=$_POST['name']; $comment=$_POST['comment']; $submit=$_POST['submit']; if($submit) { if($name&&$comment) { $query=mysql_query("INSERT INTO comment (id,name,comment) VALUES ('','$name','$comment')"); } else { echo "Please fill out all the fields."; } } $query_Recordset1 = "SELECT `id`, `name`, `photopath`, `state` FROM photo ORDER BY `name` ASC"; $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); ?> <body> <div id="comments"> <form action="image_show.php?id=<?php echo $row_Recordset1['id'];?>" method="POST"> <label>Name: </label><br /><input type="text" name="name" input id="name"value="<?php echo "$name" ?>" /><br /><br /> <label>Comment: </label><br /><input type="text" input id="comment"/><textarea name="comment" "cols="25" rows="7"></textarea><br /><br /><br /> <input type="submit" name="submit" value="Comment" /><br /> </form></div> <hr width="1100px" size="5px" /> </body> <?php $query=mysql_query("SELECT * FROM comment ORDER BY id DESC"); while($rows=mysql_fetch_assoc($query)) { $id=$rows['id']; $name=$rows['name']; $comment=$rows['comment']; $linkdel="<a href=\"delete.php?id=" . $rows['id'] . "\">Delete User</a>"; echo '<font color="red">Name:</font> ' . $name . '<br />' . '<br />' . '<font color="red">Comments:</font> ' . '<br />' . $comment . ' ' . ' ' . ' ' . ' ' . $linkdel . '<br />' . '<br />' . '<hr size="5px" width="500px" color="blue" />' ; } ?> </html> </body> </html> and let me know what you get Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 same. "bad photo id" no url id and when i go to delete a comment the error disappears and all thats left is the comment box and Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/20/7812420/html/comment.php on line 33. Seems like every pass this page takes it loses info. first loses picture then when deleting a comment it loses error Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 well i know why your photo id is dissapearing, when you click on the photo link <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src='<?php echo $row_Recordset1['photopath'] ;?>' height="100" width="100"/></a> it is setting the url to image_show.php?id=<?php echo $row_Recordset1['id'];?/> however, when you post a comment, you have the action set to just image_show.php therefore when the form is submitted, you are going from a dynamic url to plain image_show.php, thus you lose your id Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 no the form action is <form action="image_show.php?id=<?php echo $row_Recordset1['id'];?>" method="POST"> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 it is now since i told you to change it, im perplexed as to why it is still not showing an id...what does you "view source" on your browser show the photo id being now? Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 no the action has been that way. I changed it while we've been talking. The first code i posted had only image_show.php. Heres the view source. Its odd that the delete function has the id of the photo: <a href="delete.php?id=22">Delete User</a> BAD PHOTO ID<body> <div id="comments"> <form action="image_show.php?id=" method="POST"> <label>Name: </label><br /><input type="text" name="name" input id="name"value="chri" /><br /><br /> <label>Comment: </label><br /><input type="text" input id="comment"/><textarea name="comment" "cols="25" rows="7"></textarea><br /><br /><br /> <input type="submit" name="submit" value="Comment" /><br /> </form></div> <hr width="1100px" size="5px" /> </body> <font color="red">Name:</font> chri<br /><br /><font color="red">Comments:</font> <br />jkokjmn    <a href="delete.php?id=22">Delete User</a> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 can i see your delete script please Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 I haven't looked at this in a bit probably should've I think I see some problems. <?php require('connect.php'); $deleteid=$_GET['id']; mysql_query("DELETE FROM comment WHERE id='$deleteid'"); header("location: success.php"); ?> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 can i see the form that sends to this page too please Quote Link to comment 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.