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. - <?php
-
include("db_connect.php");
-
include("functions.php");
-
?>
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<script type='text/javascript' src='jquery.pack.js'></script>
-
<script type='text/javascript'>
-
$(function(){
-
$("a.reply").click(function() {
-
var id = $(this).attr("id");
-
$("#parent_id").attr("value", id);
-
});
-
});
-
</script>
-
-
<title>Threaded Comments</title>
-
</head>
-
<body>
-
<div id='wrapper'>
-
<ul>
-
<?php
-
$q = "SELECT * FROM comment WHERE parent_id = 0";
-
$r = mysql_query($q);
-
while($row = mysql_fetch_assoc($r)):
-
getComments($row);
-
endwhile;
-
?>
-
</ul>
-
<form id="comment_form" action="post_comment.php" method='post'>
-
<label for="name">Name:</label>
-
<input type="text" name="name" id='name'/>
-
<label for="comment_body">Comment:</label>
-
<textarea name="comment_body" id='comment_body'></textarea>
-
<input type='hidden' name='parent_id' id='parent_id' value='0'/>
-
<div id='submit_button'>
-
<input type="submit" value="Add comment"/>
-
</div>
-
</form>
-
- <?php
-
function getComments($row) {
-
echo "<li class='comment'>";
-
echo "<div class='name'>".$row['name']."</div>";
-
echo "<div class='comment_body'>".$row['comment']."</div>";
-
echo "<div class='timestamp'>".$row['created_at']."</div>";
-
echo "<a href='#comment_form' class='reply' id='".$row['id']."'>Reply</a>";
-
/* The following sql checks whether there's any reply for the comment */
-
$q = "SELECT * FROM comment WHERE parent_id = ".$row['id']."";
-
$r = mysql_query($q);
-
if(mysql_num_rows($r)>0) // there is at least reply
-
{
-
echo "<ul>";
-
while($row = mysql_fetch_assoc($r)) {
-
getComments($row);
-
}
-
echo "</ul>";
-
}
-
echo "</li>";
-
}
-
?>
- <?php
-
include("db_connect.php");
-
$name = mysql_real_escape_string($_POST['name']);
-
$comment_body = mysql_real_escape_string($_POST['comment_body']);
-
$parent_id = mysql_real_escape_string($_POST['parent_id']);
-
-
$q = "INSERT INTO comment (name, comment, parent_id) VALUES ('$name', '$comment_body', '$parent_id')";
-
$r = mysql_query($q);
-
if(mysql_affected_rows()==1) {
-
header("location: index.php");
-
}
-
else {
-
echo "Comment cannot be posted. Please try again.";
-
}
-
?>
Thank you in advance.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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?
|
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...
|
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...
| |
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...
|
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?
|
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...
|
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...
|
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
#...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |