title: Posting data using Ajax
body: <p>I've been trying to post data using AJAX that will update a field in my database however I am having trouble doing so. Everything seems like it should run fine and I get no errors in the console but I've no idea why my db won't update.</p>
  
  <p>Can someone help me out here please?</p>
  
  <p><code>AJAX</code>:</p>
  
  <pre><code>function ajaxUpdate() {
          var arr = {var1: name, var2: age};
              $.ajax({
                  url: 'ajax/confirm.php',
                  type: 'POST',
                  data: JSON.stringify(arr),
                  contentType: 'application/json; charset=utf-8',
                  dataType: 'json',
                  success: function(data) {
                      console.log("success");
                  }
              });
          }
  </code></pre>
  
  <p><code>Confirm.php</code>:</p>
  
  <pre><code>$name=$_POST['var1'];
  $age=$_POST['var2'];
  
  if($name == "Stuart") {
      mysqli_query($connection,"UPDATE people SET age='$age'");
  }
  else if($name == "Peter") {
      mysqli_query($connection,"UPDATE people SET age='$age'");
  }
  </code></pre>
  
  <p>The connection to my database is working as I have <code>$connection</code> setup and went to the page <code>/ajax/confirm.php</code> in my browser and I see "Connection successful" in my console as I defined if successful.</p>
  
  <p>So I am unsure as to why this isn't updating? </p>
  
  <p>Are my values not being posted correctly? </p>
  
  <p>I'm new to AJAX so forgive me if this is something very simple!</p>
  
  <p>Thanks</p>