title: PHP for parsing JSON and adding to database mysql
body: <p>I am making a web app (android) with phonegap and jquery mobile.</p>
  
  <p>I am trying to send three fields from an html form as json, to a php page which will decode the json string/object (im new to json, ajax, jquery) and add the three fields as a mysql query to a database on my localhost.</p>
  
  <p>My html page looks like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){  
  $('#btn').bind('click', addvalues);
  });
    function addvalues(){
    $.ajax({  
    url: "connection.php",
    type: "POST",  
    data: "id=" + $("#id").val()+"&amp;name=" + $("#name").val() + "&amp;Address=" + $("#Address").val(),
     datatype:"json",
     success: function(status)
    {  
      if(status.success == false) 
      {  
          //alert a failure message
      } 
      else { 
            //alert a success message
          }  
     }  
   });  
  } 
  &lt;/script&gt; 
  &lt;/head&gt; 
  &lt;body&gt; 
  
  &lt;div data-role="header"&gt;
  &lt;h1&gt;My header text&lt;/h1&gt;
  &lt;/div&gt;&lt;!-- /header --&gt;
  &lt;div data-role="content"&gt;
  &lt;form id="target" method="post"&gt;
  &lt;label for="id"&gt;
  &lt;input type="text" id="id" placeholder="ID"&gt;
  &lt;/label&gt;
  &lt;label for="name"&gt;
  &lt;input type="text" id="name" placeholder="Name"&gt;
  &lt;/label&gt;
  &lt;label for="Address"&gt;
  &lt;input type="text" id="Address" placeholder="Address"&gt;
  &lt;/label&gt;
  &lt;input type="submit" id "btn" value="Add record" data-icon="star" data-theme="e"&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt; 
  </code></pre>
  
  <h2>The Question is:</h2>
  
  <p>How exactly do i extract the three fields (ID, name, Address) from the string that i have sent to my php file (connection.php)?
  connection.php is hosted by my local server.</p>
  
  <p>I am familiar with making connections to database, as also with adding queries to mysql. I only need help with extracting the three fields, as i am new to ajax and jquery and json.</p>
  
  <p>As of now, this is ALL i have done in connection.php:</p>
  
  <pre><code>&lt;?php
  $server = "localhost";
  $username = "root";
  $password = "";
  $database = "jqueryex";
  $con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
  mysql_select_db($database, $con);
  
  //I do not know how to use the json_decode function here
  
  
  //And this is how, i suppose, we will add the values to my table 'sample'
  $sql = "INSERT INTO sample (id, name, Address) ";
  $sql .= "VALUES ($id, '$name', '$Address')";
  if (!mysql_query($sql, $con)) {
  die('Error: ' . mysql_error());
  } else {
  echo "Comment added";
  }
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>Please add the relevant code in this file and help me out.
  I will be highly obliged.
  :)</p>