kleb Posted December 30, 2011 Share Posted December 30, 2011 i need help with this issue.i designed a comment page where people can comment on a topic but what i descovered is that once i comment on a topic it will be showed on the page i asked it to go but if i comment on thesame topic it will not show exceeptb the one that as been there before.even if i click on anotherr topic and i comment once i cannot comment again but if i remove the WHERE clause all the comments meant for other topics will just display which is not good.Please help me thanks. this is my code: <?php include"header.php"; $topicid=$_GET['id']; ///the two tables POST and TOPICS share thesame id $sql="SELECT post_comments FROM post WHERE $topicid=topicsID"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['post_comments']}"; } ?> Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2011 Share Posted December 30, 2011 That looks correct. Could you let us see your HTML form for the comment as well as the INSERT query? May need the table information from your database as well... Quote Link to comment Share on other sites More sharing options...
kleb Posted December 30, 2011 Author Share Posted December 30, 2011 does my insert hv anything to do wit it? anyway i would hv loved to show t code but am replying ths thread via phone Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted December 31, 2011 Share Posted December 31, 2011 yeah, we will need to see your logic for this one.. any relevant code will be helpful. Quote Link to comment Share on other sites More sharing options...
kleb Posted December 31, 2011 Author Share Posted December 31, 2011 :'(can any one give me the right codes?guys i want to add a comment page to some articles on my site.i have created a table where the comments will go and when a visitor clicks on any of the articles it will show the comments by previous visitors.pls note that i dont want comment made for article a to sbow in article b..just like php freaks.thanks.happy newyear to you. Quote Link to comment Share on other sites More sharing options...
trq Posted December 31, 2011 Share Posted December 31, 2011 I think your missing the point of a help forum. The idea is you write the code and ask us questions when your stuck. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted December 31, 2011 Share Posted December 31, 2011 I think your missing the point of a help forum. The idea is you write the code and ask us questions when your stuck. agreed. OP, do you have any code to show for this? Quote Link to comment Share on other sites More sharing options...
kleb Posted December 31, 2011 Author Share Posted December 31, 2011 i wrote a code b4 but since it just displayed all the comments,i deleted it Quote Link to comment Share on other sites More sharing options...
Mavent Posted December 31, 2011 Share Posted December 31, 2011 i wrote a code b4 but since it just displayed all the comments,i deleted it How do you want the comments displayed? By date, member, or just a hard number? I'll be honest with you-if you're just looking for Blog-style comments, the easiest thing you could do is install Wordpress and let it handled the comments for you. Barring that, create a Date field in your table that holds the comments, and then grab a date range to display. If you could be a little more specific, I could probably post some examples for you. Is the only parameter that the comments can't appear on the same page as the article? Because that's very, very easy. All you have to do is build a discreet link for each article, and link out to it from a "view comments" button. I have to believe that there's more to your request, because it would literally be more work to make the comments appear on the same page with the articles than it would be to have them appear on a separate page. Quote Link to comment Share on other sites More sharing options...
kleb Posted December 31, 2011 Author Share Posted December 31, 2011 mavent you are the only one that understood me well..yes i want the comments to apear on the article page and not in another page.one thing i discover was when i tried to display the comments by id,i.e i said WHERE articleid=commentid (i joined the two tables with a common id called articleid)it should display the records but what i discover is that it will only display one comment and leave the rest although i understand why that happend but i dont know what to write in the WHERE clause so that other comments made on an article will appear on that same article page.am replying you via mobile so i cant post a code now thanks Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted December 31, 2011 Share Posted December 31, 2011 We understood you fine, but we don't provide free scripts here. We help you to finish your own Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted December 31, 2011 Share Posted December 31, 2011 We understood you fine, but we don't provide free scripts here. We help you to finish your own This. We're here to help, not do all of your work for you. If you need help, show us some code. If you simply want someone to do all the work for you, post in the 'Freelance' section. Quote Link to comment Share on other sites More sharing options...
kleb Posted January 1, 2012 Author Share Posted January 1, 2012 ok.i will write the code again and post it Quote Link to comment Share on other sites More sharing options...
kleb Posted January 1, 2012 Author Share Posted January 1, 2012 this is my insert page: 17223_.php Quote Link to comment Share on other sites More sharing options...
kleb Posted January 1, 2012 Author Share Posted January 1, 2012 this is my insert code: 17224_.php Quote Link to comment Share on other sites More sharing options...
kleb Posted January 1, 2012 Author Share Posted January 1, 2012 this is my select page: 17225_.php Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 1, 2012 Share Posted January 1, 2012 Your insert query does not contain a topicsID. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 the field name needs to be before the value. $sql="SELECT post_comments FROM post WHERE $topicid=topicsID"; // reverse $topicsID and $topicid $sql="SELECT post_comments FROM post WHERE topicsID = $topicid"; //correct Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 post your code directly onto this thread, very few people will download a file given from a user. Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 1, 2012 Share Posted January 1, 2012 This is his code: reply.php <?php include"header.php"; if(isset($_POST['submit'])) { $comment=mysql_real_escape_string(trim($_POST['comment'])); $name=mysql_real_escape_string(trim($_POST['name'])); if($comment!=='' && $name!=='') { $ins="INSERT INTO post(post_content,post_by)VALUES('$comment','$name')"; mysql_query($ins) or die(mysql_error()); if($ins)echo"succesfull, you can click back to view your comment and other new comments</a>"; } else { echo"You can not post an empty page or leave your name blank"; } } ?> comments.php <?php include"header.php"; $topicid=$_GET['id']; ///please note that i joined the two tables POST and TOPICS with a common id(topicsID); $sql="SELECT post_content,post_by FROM post WHERE $topicid=topicsID"; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<strong>{$row['post_by']}</strong>: {$row['post_content']}"."</br>"; } ?> So. This is wrong: $sql="SELECT post_content,post_by FROM post WHERE $topicid=topicsID"; It should be: $sql="SELECT post_content,post_by FROM post WHERE topicsID='$topicid'"; In reply.php you don't enter the topic ID, only the content and name...so you can never retrieve it. And you don't escape or validate the $topicid in comments.php. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 This is his code: reply.php <?php include"header.php"; if(isset($_POST['submit'])) { $comment=mysql_real_escape_string(trim($_POST['comment'])); $name=mysql_real_escape_string(trim($_POST['name'])); if($comment!=='' && $name!=='') { $ins="INSERT INTO post(post_content,post_by)VALUES('$comment','$name')"; mysql_query($ins) or die(mysql_error()); if($ins)echo"succesfull, you can click back to view your comment and other new comments</a>"; } else { echo"You can not post an empty page or leave your name blank"; } } ?> comments.php <?php include"header.php"; $topicid=$_GET['id']; ///please note that i joined the two tables POST and TOPICS with a common id(topicsID); $sql="SELECT post_content,post_by FROM post WHERE $topicid=topicsID"; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<strong>{$row['post_by']}</strong>: {$row['post_content']}"."</br>"; } ?> So. This is wrong: $sql="SELECT post_content,post_by FROM post WHERE $topicid=topicsID"; It should be: $sql="SELECT post_content,post_by FROM post WHERE topicsID='$topicid'"; In reply.php you don't enter the topic ID, only the content and name...so you can never retrieve it. And you don't escape or validate the $topicid in comments.php. i actually commented on the same error in another one of his threads. Kleb, please do not post multiple threads on the same topic. Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 1, 2012 Share Posted January 1, 2012 the field name needs to be before the value. $sql="SELECT post_comments FROM post WHERE $topicid=topicsID"; // reverse $topicsID and $topicid $sql="SELECT post_comments FROM post WHERE topicsID = $topicid"; //correct While convention has you list the column first, it will work either way. Quote Link to comment Share on other sites More sharing options...
kleb Posted January 1, 2012 Author Share Posted January 1, 2012 let me try it Quote Link to comment Share on other sites More sharing options...
kleb Posted January 1, 2012 Author Share Posted January 1, 2012 thanks so much at every one,am highly greatfull Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 the field name needs to be before the value. $sql="SELECT post_comments FROM post WHERE $topicid=topicsID"; // reverse $topicsID and $topicid $sql="SELECT post_comments FROM post WHERE topicsID = $topicid"; //correct While convention has you list the column first, it will work either way. learned something new then 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.