title: Displaying a success message after form submission
body: <p>I'm trying to understand jquery and particularly inserting and displaying data in a mysql table using ajax.</p>
  
  <p>I have been experimenting with this code which inserts and displays records from a mysql database. I'm now trying to get it to display the success message in the div with the id "info" whilst also displaying all the records. I seem to only do one but never both. Many thanks.</p>
  
  <p>form.php</p>
  
  <p>
     </p>
  
  <p></p>
  
  <pre><code>     &lt;script   src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;
    &lt;/script&gt;
    &lt;script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
   &lt;script type="text/javascript"&gt;
             $(document).ready(function(){
  
                  function showComment(){
                    $.ajax({
                      type:"post",
                      url:"process_ajax.php",
                      data:"action=showcomment",
                      success:function(data){
                           $("#comment").html(data);
  
                      }
                    });
                  }
                  showComment();
  
                  $("#button").click(function(){
  
                        var username=$("#username").val();
                        var review=$("#review").val();
  
                        $.ajax({
                            type:"post",
                   url:"process_ajax.php",
                                   data:"username="+username+"&amp;review="+review+"&amp;action=addcomment",
                     success:function(data){
                         $("#info").html(data);
                           }
  
                        });
  
                  });
             });
     &lt;/script&gt;
    &lt;/head&gt;
  
     &lt;body&gt;
      &lt;form&gt;
       Username : &lt;input type="text" name="username" id="username"/&gt;
             &lt;/br&gt;
             Review : &lt;input type="text" name="review" id="review" /&gt;
             &lt;/br&gt;
             &lt;input type="button" value="Send Comment" id="button"&gt;
              &lt;/form&gt;
           &lt;div id="info" /&gt;
             &lt;ul id="comment"&gt;&lt;/ul&gt;
  
     &lt;/body&gt;
     &lt;/html&gt;
  </code></pre>
  
  <p>Process_ajax.php</p>
  
  <pre><code>  &lt;?php
   include_once("db_conx.php");
  
   $action=$_POST["action"];
    if($action=="showcomment"){
    $show="Select * from user_reviews ORDER by date desc";
    $result = $db_conx-&gt;query($show);
   while($row=mysqli_fetch_array($result)){
      echo "&lt;li&gt;&lt;b&gt;$row[username]&lt;/b&gt; : $row[review]&lt;/li&gt;";
      }
      }
     else if($action=="addcomment"){
   $username= ($_POST['username']);
   $review= ($_POST['review']);
  
    $stmt = $db_conx-&gt;prepare('INSERT user_reviews SET username = ?,   review=?');
  $stmt-&gt;bind_param('ss', $username, $review);
  $stmt-&gt;execute();
  if ($stmt-&gt;errno) {
   echo "There was an error in saving your review. Please try again." .          $stmt-&gt;error;
     }else{
     echo "Your review has been saved";
   }
   }
   ?&gt;
  </code></pre>