title: Comment-reply system post succesfully comments without refreshing page, but not replies
body: <p>I have created a php, jquery comment-reply system that works perfect. It works like facebook. User posts a comment and then a user can add a reply. Jquery used in order to view comments without refreshing the page each time a user posts a comment. Although I did this and works with comments, it is not working with the relies. In order to view replies I have to refresh the page. Any idea how to fix this?</p>
  
  <p>This is my main page, wall.php :</p>
  
  <pre><code>&lt;?php
  &lt;script&gt; 
   $(document).ready(function(){                          
    $("#comment_process").click(function(){
      if($("#comment_text").val() != ""){ 
          $.post("comments.php?action=post", { comment: $("#comment_text").val() }, function(data) {
              $(".comments").html(data);
              $("#comment_text").val("");
           });
         } 
       });   
     });   
  &lt;/script&gt;
  
  &lt;div class="comment_container"&gt; &lt;div class="comment_form"&gt;
  &lt;textarea id="comment_text"/&gt; &lt;/textarea&gt;
  &lt;/div&gt;&lt;/div&gt;
  &lt;div class="comments"&gt;  &lt;?php include_once("comments.php");?&gt;    &lt;/div&gt;
  ?&gt;
  </code></pre>
  
  <p>The next page called comments.php :</p>
  
  <pre><code>&lt;?php
   require_once('core/init.php');
  &lt;script&gt;
  $(document).ready(function(){   
  $('.reply').keyup(function(e){
      if(e.keyCode == 13){
          var comments_id = $(this).attr('comments_id');
          var reply = $(this).val();
          $.post('reply.php', {"data_comments_id":comments_id, "data_reply":reply});  
          $('.reply').val('');    
        }
      });
    });
  &lt;/script&gt;
  
  function getComments(){
  $comments = "";
  $sql = mysql_query("SELECT * FROM comments ORDER BY comment_date DESC ") or die (mysql_error());
  if(mysql_num_rows($sql) == 0){
    $comments = " &lt;div class='each_comment'&gt; There are no comments ...&lt;/div&gt; ";
  }
  else
  {   
     while ($row= mysql_fetch_assoc($sql)) {
  
      $comments .= "Says : &lt;div class='each_comment'&gt; ".$row['comment_date']." ".$row['comment'];
      $comments .= "&lt;input type='text' class='reply' comments_id='{$row['comments_id']}' /&gt;";
  
      echo "&lt;div class='replies'&gt;";
      $reply_query = mysql_query("SELECT reply_id, reply, reply_date FROM comments_reply WHERE comments_id='{$row['comments_id']}' ");
  
      while ($run_reply= mysql_fetch_assoc($reply_query)) {
        $reply_id = $run_reply['reply_id'];
        $reply = $run_reply['reply'];
        $reply_date = $run_reply['reply_date'];                               
      $comments .= "Replied: $reply_date  $reply   ";
  
      echo"&lt;/div&gt;";
  
      $comments .= "&lt;/div&gt;"; 
    }
   }
  return $comments;  
  }
  
  function postComments($comment){
   $comment = mysql_real_escape_string(strip_tags($comment));
   if(isset($comment) &amp;&amp; empty($comment)){
      $sql = mysql_query(" INSERT INTO `comments` (comment, comment_date) VALUES ('".$comment."', now()) ");
   }
   return getComments();
  }
  
  if((isset($_GET['action'])) &amp;&amp; ($_GET['action'] == "post")) {
  postComments($_POST['comment']);
  }
  
  echo getComments();        
  ?&gt;
  </code></pre>
  
  <p>and finally this is my reply.php page  :</p>
  
  <pre><code>&lt;?php  
  require_once('core/init.php');
  
  $comments_id = $_POST['data_comments_id'];
  $reply = $_POST['data_reply'];
  
  if(isset($reply) &amp;&amp; !empty($reply)){ 
      mysql_query("INSERT INTO comments_reply VALUES ('', '$comments_id', '$reply', now()) "); 
  }
  
  ?&gt;
  </code></pre>