title: Updating database using JSON and PHP
body: <p>I really appriciate your help, i am loseing my mind here
  I don't get any errors, everything seems ok, but the db is not updating?!!!</p>
  
  <p>in firefox consol i get no error and on the server log no error ?!!</p>
  
  <p>i get the alert saying insert successful!!
  but as i said, my db dosent update?!</p>
  
  <p>here is my code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="landmark-1" data-landmark-id="1"&gt;
  &lt;form  id="insertContact" &gt;
  
  
      &lt;input name="a1" id="a1" type="text" placeholder="" onFocus="$(this).val('')" value=""&gt;
      &lt;label&gt; name &lt;/label&gt;
    
   
      &lt;input name="a2" id="a2" type="text" placeholder="" onFocus="$(this).val('')" value=""&gt;
      &lt;label&gt;message&lt;/label&gt;
  
  
  &lt;input type="submit" 
    id="submit" name="submit" value="Submit" /&gt;
   &lt;/form&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and this is my js file</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  $(document).ready(function(){
      $("#submit").click(insertContact);
    });
    function insertContact(){
      console.log("Entering insertContact()");
    $("#insertContact :input").serializeArray(),
      $.post("update.php",
    
      function(json){
        if(json== null || json == 'undefined')
          alert("Insert failed");
        else
          alert("Insert successful");
    
      });
      return false;
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>and this is my php file</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Methods: POST');
  
  $server = "localhost";
  $username = "xxxxxxx";
  $password = "xxxxxxx";
  $database = "xxxxxxx";
  
  $con = mysql_connect($server, $username , $password) or die ("Could not connect: " . mysql_error());
  mysql_select_db($database, $con);
  $iid=1;
  $ab1 = mysql_real_escape_string($_POST["a1"]);
  $ab2 = mysql_real_escape_string($_POST["a2"]);
  
  
  
  $sql = "UPDATE my_table SET
   field_1='$ab1',
   field_2='$ab2'
  
   
   WHERE id=$iid";</code></pre>
  </div>
  </div>
  </p>