473,545 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ 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 5386
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
2618
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
5637
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 to the appropriate mode and test the html form it gave me an 500 internel server error. I really need it to be done soon, I would not post here...
0
1487
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 worth of comments. Is there any way of retrieving the posted forms from the server?
0
1033
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 using the value="" param) have it pass "yes". I thought of writing a function for the onClick, but wasn't sure if I can change the form object that...
8
9272
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
1740
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 node.nextSibling.nextSibling.innerHTML="" 25 } My thought is that when i clicked a link,the js function generate the Form,then get the input and deal with...
3
1753
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 working quite ok, but I need to make it AJAX - the main reason is, that I DONT NEED PAGE TO BE RELOADED. What can You suggest?
2
6925
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 of an auto-number and an Alpha expression. The subform that links fine is a comments form (continuous form with just date field and memo box) and the...
5
16549
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 the only problem is that I can't think up a way to let people reply to an already-posted comment... Anyway, I have a MySQL database called...
5
2286
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 email. however all the information is missing form the email I only get the first form text field?? #!/bin/perl #...
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.