Note that there are some explanatory texts on larger screens.

plurals
  1. POduplicate mysql comment entries with ajax powered social network?
    text
    copied!<p>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.</p> <p>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</p> <p>Thanks jquery </p> <pre><code> $(".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 + '&amp;postid=' + postid + '&amp;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); } }); } }); }); </code></pre> <p>php giving double post when comment uploaded</p> <pre><code> &lt;? $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)){?&gt; &lt;? $pid = $row['pid']; $formattime = date("g:i:a",$row['posttime']); echo '&lt;p class="speechbubble"&gt;'.$row['post'].'&lt;/p&gt;'; echo '&lt;p class="msgholder" &gt;Posted by '.$row['name'].' at '.$formattime. '&lt;img class= "userprofileimage" src="'.$row['uid_imageurl'].'" alt="user profile image"/&gt;&lt;/p&gt;'; ?&gt; &lt;div class="editable" pid="&lt;? echo $row['pid'];?&gt;" contentEditable="true"&gt; add comment... &lt;/div&gt; &lt;? $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 '&lt;p&gt;Comments&lt;/p&gt;&lt;hr&gt;&lt;br&gt;'; echo 'This post has no comments yet, be the first!'; echo '&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;br&gt;'; }else{ echo '&lt;p&gt;Comments&lt;/p&gt;&lt;hr&gt;&lt;br&gt;'; while($row=mysql_fetch_assoc($result_comments)){ $formattime_comment = date("g:i:a",$row['comment_time']); echo '&lt;p class="comment"&gt;'.$row['comment'].'&lt;/p&gt;'; echo '&lt;p class="commentposter"&gt;posted by '.$row['name']. ' at ' .$formattime_comment. '&lt;img class="commentprofileimage" src="'.$row['uid_imageurl'].'" alt="user profile image"/&gt;&lt;/p&gt;'; }//$sql_comments echo '&lt;hr&gt;&lt;br&gt;&lt;br&gt;'; }//else end }//$sql ?&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> -->
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload