Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3804884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:35:23+00:00 2026-05-19T14:35:23+00:00

I want to add a comment system after my article, php part code <?php

  • 0

I want to add a comment system after my article,

php part code

<?php
...
while($result = mysql_fetch_array($resultset))
{
$article_title = $result['article_title'];
...
?>
<form id="postform" class="postform">
<input type="hidden" name="title" id="title" value="<?=$article_title;?>" />
<input type="text" name="content" id="content" />
<input type="button" value="Submit" class="Submit" />
</form>
...
<?php
}
?>

ajax part:

$(function($) {
$(document).ready(function(){
$(".Submit").click(function(){
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
var anyBlank = 0;
if(anyBlank == "0")
{
var title    = $("#title").val();
var content   = $("#content").val();
$.ajax({
type: "POST",
url: "ajax_post.php",
data: "title="+title+"&content="+content,
success: function(date_added){
if(date_added != 0)
{
structure = '<div class="comment_date_added">'+date_added+'</div><div id="comment_text"><div id="comment_content">'+content+'</div>';                   
$("#post_comment").prepend(structure);
}
});
});

ajax_post.php

echo $title;
echo $content;//get $title and $content and insert into database.

my question: <form id="postform" class="postform"> is written into a MYSQL_QUERY result circle. how to modify ajax part so that every div.submit can post its own value to ajax_post.php and then return the data into $("#post_comment").prepend(structure); Thanks to all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:35:24+00:00Added an answer on May 19, 2026 at 2:35 pm

    You have to give the input fields a class instead of an ID. IDs have to be unique in an HTML document:

    <form class="postform">
        <input type="hidden" name="title" class="title" value="<?=$article_title;?>" />
        <input type="text" name="content" class="content" />
        <input type="button" value="Submit" class="Submit" />
    </form>
    

    Then you can make the data lookup relative to the clicked element:

    var title = $(this).siblings('.title').val();
    var content = $(this).siblings('.content').val();
    

    I also suggest to pass an object to the data attribute for automatic URL encoding of the values:

    data: {title: title, content: content}
    

    Then, when you create a new entry for the #post_comment section, you have to give these elements also a class instead of an ID (and don’t forget to use var!):

    var structure = '<div class="comment_date_added">'+date_added+'</div><div class="comment_text"><div class="comment_content">'+content+'</div>';
    

    or more jQuery like:

    $('<div />', {class:'comment_data_added'})
    .append($('<div />', {class: 'comment_date_added', text: date_added}))
    .append($('<div />', {class: 'comment_content', text: content}))
    .prependTo('#post_comment');
    

    Further notes:

    • You have somehow a nested ready() handler:

      $(function($) {                     //   <--┐
          $(document).ready(function(){   //   <--┴- this is the same
              //...
          });
      });
      

      Either do:

      jQuery.noConflict();
      jQuery(function($) {
          $('.Submit')...
      )};
      

      or

      $(function() {
          $('.Submit')...
      )};
      
    • This part in the click handler:

      var id = $(this).attr("id");
      var name = $(this).attr("name");
      var dataString = 'id='+ id ;
      var parent = $(this);
      var anyBlank = 0;
      

      does not seem to do anything. Besides that, the submit button has no ID and no name.

    • Depending on the further structure of your PHP code, you should have a look at the alternative syntax for control structures. It makes easier to mix PHP and HTML without fiddling around with brackets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have dbml with single table users i want add partial class for User
I want to add a column to an existing legacy database and write a
I want to add a constant value onto an incoming bound integer. In fact
I want to add a scheduled task to a client's ASP.NET app. These posts
I want to add a mailto link on our web page. I want to
I want to add a property to my User model that returns the number
I want to add a comma in the thousands place for a number. Would
I want to add same field to multiple tables. Can I do this with
I want to add my own member to the StringBuilder class, but when I
I want to add the option of automatic port forwarding (NAT Traversal) to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.