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 7003909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:07:48+00:00 2026-05-27T21:07:48+00:00

trying to solve a bug! I have an ajax powered social network (with like

  • 0

trying to solve a bug! I have an ajax powered social network (with like and comments etc). I have a working comment script but when i have tested it I am getting a duplication of the original post and comment. Instead of adding a comment to just the post it is adding the comments and duplicating the post and comments each time when the data is output.

I have used jquery for ajax which works fine and PHP, probably something obvious as i new to jquery and php I was hoping for some help? Sorry for the armount of code I can reduce if required

Thanks
jquery

       $(".editable").live('click', function(){


        $(this).empty();

        $(this).mouseout(function() {

            var comment = $(this).html();
            var postid = $(this).attr("pid");
            var commentuserid = $("#loggedin").attr("uid");


            if(comment == ""){

                return false;


            }else{


                    //alert(comment);
                    //alert(postid);
                    //alert(commentuserid);


                    var datastring = 'comment=' + comment + '&postid=' + postid + '&commentuserid=' + commentuserid;


                    //save with ajax clear box and then load back in
                    $.ajax({
                    type: "POST",
                    url: "uploadcomment.php",
                    data: datastring,
                    success: function(data){


                    $(".usermsg").html(data);




                    }

                    });


            }
});



});

php giving double post when comment uploaded

     <?

    $sql = "SELECT post.post, post.posttime, post.pid_imageurl, post.likes, user.name, 
    comments.comment, user.uid_imageurl, comments.comment_uid, post.pid
                FROM post
                INNER JOIN user
                ON post.uid=user.uid
                LEFT JOIN comments
                ON comments.comment_pid=post.pid
                ORDER BY pid DESC";

    $result = mysql_query($sql);

    while($row=mysql_fetch_assoc($result)){?>

    <?
    $pid = $row['pid'];
    $formattime = date("g:i:a",$row['posttime']);
    echo '<p class="speechbubble">'.$row['post'].'</p>';
    echo '<p class="msgholder" >Posted by '.$row['name'].' at '.$formattime. '<img class= "userprofileimage" src="'.$row['uid_imageurl'].'" alt="user profile image"/></p>';
?>



    <div class="editable" pid="<? echo $row['pid'];?>" contentEditable="true">
             add comment...
    </div>

    <?

    $sql_comments = "SELECT comments.comment, comments.comment_time, user.name, user.uid_imageurl FROM comments
                    INNER JOIN user
                    ON  comments.comment_uid = user.uid
                    WHERE comment_pid = '$pid' ORDER BY cid DESC";


    $result_comments = mysql_query($sql_comments);                

      $numrows_comments=mysql_num_rows($result_comments);//num of rows


              if($numrows_comments==0) //no comments
            {
                 echo '<p>Comments</p><hr><br>';
                 echo 'This post has no comments yet, be the first!';
                 echo '<br><br><br><hr><br><br>';

            }else{
                  echo '<p>Comments</p><hr><br>';
                  while($row=mysql_fetch_assoc($result_comments)){
                  $formattime_comment = date("g:i:a",$row['comment_time']);
                   echo '<p class="comment">'.$row['comment'].'</p>';
                   echo '<p class="commentposter">posted by '.$row['name']. ' at ' .$formattime_comment. '<img class="commentprofileimage" src="'.$row['uid_imageurl'].'" alt="user profile image"/></p>';

            }//$sql_comments

            echo '<hr><br><br>';

      }//else end

    }//$sql


    ?>




    </div>









</div>

–>

  • 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-27T21:07:49+00:00Added an answer on May 27, 2026 at 9:07 pm

    I would first be inclined to believe

    $(".usermsg").html(data);
    

    should be altering the html of another element. It is possible your ajax is returning the whole html and adding that to just an inner element and not the container. If this is the case, alter your php to return only the comment that was posted, or change this

    $(".usermsg").html(data); 
    

    to the container element. In this case, it is not duplicating, it is just adding extra html to the loaded page.

    as a side note, it is definitely better to replace the whole comment block – depending on how you handle the page – than to just place in the comment that was added. This way your html will update if another user happened to be commenting as well. It will keep your comments as up to date as possible.
    Little different if you are paginating, happen to be on some inner page and enough other comments were added to push the user to another page of comments. That’s another story though.

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

Sidebar

Related Questions

In trying to solve the ajax back button problem I have found the Really
I have been trying to solve this bug for awhile now. It's a CXF,
I have been trying to solve this bug for 2 days straight and can't
Trying to solve a problem with templatetags. I have two templatetags: @register.inclusion_tag('directory/_alphabet.html') def alphabet_list(names):
Trying to solve this problem . I would like to learn how the bootstrapper
I'm trying to solve the 3n+1 problem and I have a for loop that
I'm trying to solve the problem of passing a 2-dimensional table into JavaScript AJAX
This problem may be a bug. i have spent too much time trying to
I'm trying to understand something that , by googling around, seems like a bug
I'm trying to implement a discrete fourier transform, but it's not working. I'm probably

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.