calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 its the original post: <!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> <?php $hostname='yoddce.com'; $username='yd29'; $password='Ad1!'; $dbname='d9'; $usertable='do'; mysql_connect('yourdddd!') or die(mysql_error()); mysql_select_db("d") 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=\"350px\" />". "<br /> "; echo $row['name']. "\n". "<br/>"; echo $row['state']. "\n"; } else { echo 'BAD PHOTO ID'; } ?> <?php $hostname='dm'; $username='yd'; $password='d1!'; $dbname='d9'; $usertable='dto'; $myconn=mysql_connect('yddd!') or die(mysql_error()); mysql_select_db("dd") 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> Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 this could be another problem: this is the comment success page <?php header("Location: image_show.php"); ?> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 yes that will need to be changed to, your form and header need to go to the dynamically created page, not the base page okay so change this $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); ?> to $query_Recordset1 = "SELECT * FROM photo"; $Recordset1 = mysql_query($query_Recordset1) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); ?> Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 did you want me to change all this: $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; ?> or just this part: $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); tried it and same old bad photo id but thats with only changing the 5 lines of code above Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 thanks for the help fugix. I'll see if I can get this working tomorrow. Later Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 hey im back...fell asleep last night. i wanted you to change the query code that i posted, for you image_show.php so you would have 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> <?php $hostname='yoddce.com'; $username='yd29'; $password='Ad1!'; $dbname='d9'; $usertable='do'; mysql_connect('yourdddd!') or die(mysql_error()); mysql_select_db("d") 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=\"350px\" />". "<br /> "; echo $row['name']. "\n". "<br/>"; echo $row['state']. "\n"; } else { echo 'BAD PHOTO ID'; } ?> <?php $hostname='dm'; $username='yd'; $password='d1!'; $dbname='d9'; $usertable='dto'; $myconn=mysql_connect('yddd!') or die(mysql_error()); mysql_select_db("dd") 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 * FROM photo"; $Recordset1 = mysql_query($query_Recordset1) 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> Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 hey man. Thanks for coming back. SO i changed that code ran it posted a comment and now instead of getting bad photo id when publishing a comment the url defaults back. example: before php?id=46 after posting: php?id=32 defaults to this photo regardless of the thumbnail clicked but at least there's a photo,right? when you click delete thats when you get a bad photo id Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 okay well thats good. Basically what you need is however you got the photoid for the pictures...i think you got it from you database...you need to use that same id as your action in your comment form....thats what im trying to do here....if you know what im talking about you will have an easier time doing it since you coded it Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 ok im back I had to run out. the ids are coming from the db. but why default to that certain photo? Im gonna try a few things. Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 i just saw that in the view source the id=32 when the url reads id=46 on same page. Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 ok i got it. had to change the query. added "WHERE id=$id $query_Recordset1 = "SELECT * FROM photo WHERE id=$id"; now to just get the delete function working. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 glad you got it working...sorry it took me so long to figure it out, was starting to confuse even myself. If you need help with the delete function let me know Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 no problem. as for the delete function. the redirect needs to be changed to this page? [code] "image_show.php?id=<?php echo $row_Recordset1['id'];?>" is that correct because I can't get the syntax right. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 yep, just use the same method that you used to get the id for the picture link and the form action and apply it to the redirect 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 should i be putting this in a header? header because I'm getting syntax errors when I add "image_show.php?id=<?php echo $row_Recordset1['id'];?>" Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 what errors are you receiving? Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 also, header is a php function so you wont need the php tags inside...try header("Location: image_show.php?id=$row_Recordset1['id']"); Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 made a change to the above code...took out the echo Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 thats how i wrote it as well but keep getting syntax errors <?php require('connect.php'); $deleteid=$_GET['id']; mysql_query("DELETE FROM comment WHERE id='$deleteid'"); header("Location: image_show.php?id=$row_Recordset1['id']"); // dont know what syntax error ?> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 can you show me the errors Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/20/7812420/html/delete.php on line 5 Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 i added {} around row syntax error is gone but when i delete no deletion and back to bad photo id. <?php require('connect.php'); $deleteid=$_GET['id']; mysql_query("DELETE FROM comment WHERE id='$deleteid'"); header("Location: image_show.php?id={$row_Recordset1['id']}"); ?> Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 alright whats the error you get when you add this <?php require('connect.php'); $deleteid=$_GET['id']; mysql_query("DELETE FROM comment WHERE id='$deleteid'") or die(mysql_error()); header("Location: image_show.php?id={$row_Recordset1['id']}"); ?> Quote Link to comment Share on other sites More sharing options...
calvinschools Posted May 9, 2011 Author Share Posted May 9, 2011 no database selected but here is my connect.php include <? $con = mysql_connect('a','a','a'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('a'); ?> i feel i'm insulting you when i take out the db info especially after all the times you've helped. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 9, 2011 Share Posted May 9, 2011 lol its cool, change it to this...remember to use <?php instead of <? <?php $con = mysql_connect('a','a','a') or die(mysql_error()); mysql_select_db('a') or die(mysql_error()); ?> then tell me what you get when trying to delete 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.