473,473 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

reply for comments form

5 New Member
Hai, I'm new in php and I have a problem when create reply for comments form. I try to create comments form that has reply button but every time I click reply button it not working at all. Hope someone can help me. Here is my code for comments form.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("db_connect.php");
  3. include("functions.php");
  4. ?>
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <script type='text/javascript' src='jquery.pack.js'></script>
  8. <script type='text/javascript'>
  9. $(function(){
  10.  $("a.reply").click(function() {
  11.   var id = $(this).attr("id");
  12.   $("#parent_id").attr("value", id);
  13.  });
  14. });
  15. </script>
  16.  
  17. <title>Threaded Comments</title>
  18. </head>
  19. <body>
  20. <div id='wrapper'>
  21.   <ul>
  22.     <?php
  23. $q = "SELECT * FROM comment WHERE parent_id = 0";
  24. $r = mysql_query($q);
  25. while($row = mysql_fetch_assoc($r)):
  26.  getComments($row);
  27. endwhile;
  28. ?>
  29.   </ul>
  30.   <form id="comment_form" action="post_comment.php" method='post'>
  31.     <label for="name">Name:</label>
  32.     <input type="text" name="name" id='name'/>
  33.     <label for="comment_body">Comment:</label>
  34.     <textarea name="comment_body" id='comment_body'></textarea>
  35.     <input type='hidden' name='parent_id' id='parent_id' value='0'/>
  36.     <div id='submit_button'>
  37.         <input type="submit" value="Add comment"/>
  38.     </div>
  39. </form>
  40.  
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function getComments($row) {
  3.  echo "<li class='comment'>";
  4.  echo "<div class='name'>".$row['name']."</div>";
  5.  echo "<div class='comment_body'>".$row['comment']."</div>";
  6.  echo "<div class='timestamp'>".$row['created_at']."</div>";
  7.  echo "<a href='#comment_form' class='reply' id='".$row['id']."'>Reply</a>";
  8.  /* The following sql checks whether there's any reply for the comment */
  9.  $q = "SELECT * FROM comment WHERE parent_id = ".$row['id']."";
  10.  $r = mysql_query($q);
  11.  if(mysql_num_rows($r)>0) // there is at least reply
  12.   {
  13.   echo "<ul>";
  14.   while($row = mysql_fetch_assoc($r)) {
  15.    getComments($row);
  16.   }
  17.   echo "</ul>";
  18.   }
  19.  echo "</li>";
  20. }
  21. ?>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("db_connect.php");
  3. $name = mysql_real_escape_string($_POST['name']);
  4. $comment_body = mysql_real_escape_string($_POST['comment_body']);
  5. $parent_id = mysql_real_escape_string($_POST['parent_id']);
  6.  
  7. $q = "INSERT INTO comment (name, comment, parent_id) VALUES ('$name', '$comment_body', '$parent_id')";
  8. $r = mysql_query($q);
  9. if(mysql_affected_rows()==1) {
  10.     header("location: index.php");
  11. }
  12. else {
  13. echo "Comment cannot be posted. Please try again.";
  14. }
  15. ?> 
Thank you in advance.
Nov 24 '14 #1
1 5379
Dormilich
8,658 Recognized Expert Moderator Expert
I try to create comments form that has reply button but every time I click reply button it not working at all.
1) you don’t have a reply button (you have a reply link which takes you to the form, but it may be styled as a button though)
2) your form’s button says 'add comment'
3) what do you expect to happen
4) what happens instead

and finally, the mysql functions are deprecated. use the more modern PDO or MySQLi extensions instead.
Nov 24 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Noud Aldenhoven | last post by:
Hello everyone, I was wondering how to remove comments away form a file. So that's why I made this script. =============================== #!/usr/bin/env python import sys import string
3
by: John | last post by:
Dear all, It been more than 3 days I am trying to debug this program, I interpret it using activePerl and it is giving (perl -wc code_process.pl) no error syntax but when I put it online, change...
0
by: steve | last post by:
I have a comments form that when filled in posts the comments from a text field into a database. Due to a bit of duff coding (Doh!) the database was not getting updated and i lost 50 or so posts...
0
by: ScooterMX | last post by:
I have a comments form that has a 'please respond' checkbox. When the user selects it, the mailer.aspx that I am submitting the form to only sees the checkbox as 'on'. Is there a way to (like...
8
by: Smoke | last post by:
Does anyone has any example on how to make a POST Form to a page using VB.net (not asp.net) ? Thanks...
1
by: firenet | last post by:
21 function js_reply_msg(node,g_id,u_id,par_id) 22 { 23 node.innerHTML="<FORM><TEXTAREA name=\"msg_con\"><\/TEXTAREA><br><INPUT type=\"submit\" value=\"reply\"><\/FORM>" 24 ...
3
by: blobb | last post by:
Hi all, i am new to AJAX, so need some help I want to create simple feedback (comment) form, base on AJAX. So, I have my HTML form, and even have my SQL database, and PHP script. All is...
2
by: rlamber | last post by:
Hello, I have 2 subforms in a Main form, one links fine, the other doesn't. I am trying to link them both to a "tracking ID" on the main form. The Tracking ID is a text field that is a combination...
5
helimeef
by: helimeef | last post by:
I designed a little PHP/MySQL forum (just for fun), and I have commenting set up and top threads on the homepage and whatnot. I'm relatively new to PHP, and this is the biggest project I've done, but...
5
by: simononestop | last post by:
Hi im totally new to perl this is my first go at using it (I normally use asp). I have set up a form with a cgi script from demon hosting. I have edited the script and the form works it sends me an...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.