php to jquery on form submit
<p>i have this code which ask user to input value and submit.  </p>

<p>html</p>

<pre><code> &lt;form id="myForm" method="post" action="saving.php"&gt;
            &lt;p&gt;&lt;label for="input1"&gt;Input 1:&lt;/label&gt;
                &lt;input type="text" size="10" name="input1" id="input1" /&gt;
            &lt;/p&gt;
            &lt;input id="save" name="save" type="submit" value="save" /&gt;
    &lt;/form&gt;
    &lt;p&gt;&lt;span id="thevalue"&gt;&lt;/span&gt;&lt;span id="existornot"&gt;&lt;/span&gt;&lt;/p&gt; 
</code></pre>

<p>js  </p>

<pre><code>$("#myForm").submit(function(event) {    
    event.preventDefault();      
    $("#myForm").validate(
      {     rules: {input1: "required",},
            messages: {input1: "message error input"},
            });
    if( $("#myForm").valid()){ 
        var $form = $("#myForm" ),
        url = $form.attr( "action" ), 
        insertedVal=$("#input1").val(); 

        $.post(url,{input1:insertedVal},  
          function(){

          //displaying value condition
          $("#thevalue").html(insertedVal);
          // ... msg from php to be inserted to #existornot 

          });  
       }
}); 
</code></pre>

<p>saving.php</p>

<pre><code>&lt;?php
  if(!empty($_POST['input1']))
  {
    $inputone= mysql_real_escape_string(trim($_POST['input1']));
    $result = mysql_query("SELECT COUNT(*) FROM `test_table` WHERE `name` = '$inputone' ");
      if (mysql_result($result, 0, 0) &gt; 0) 
      {
        echo "is duplicate data" ;
      } 
      else 
      {      
        mysql_query("INSERT INTO `test_table`(name)  VALUES ('$inputone')") ;
         echo "is updated to db" ;
      }
  }
  else
  {
    echo "could not be empty"  ;
  }

?&gt;
</code></pre>

<p>How to pass those message of 'is duplicate data' or ' is updated to db' from the php to the javasript, to tell user that the submit process is fail or success ?  </p>

<p>Thanks in advance for any advice.</p>
