title: AJAX Password Change
body: <p>So i am trying to implement a password change functionality to my site and I want to submit the password form <strong>without</strong> refreshing the page. So I'm trying to use ajax. Here's my html:<br></p>
  
  <pre><code>&lt;form id="change_Pass" action="" method="post"&gt;
      Current Password&lt;input type="password" id="change_password" name="change_password"&gt;&lt;br&gt;
      New Password&lt;input type="password" id="new_password" name="new_password"&gt;&lt;br&gt;
      Verify Password&lt;input type="password" id="verify_password" name="verify_password"&gt;&lt;br&gt;
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And then the jquery:<br></p>
  
  <pre><code>$('#change_Pass').submit(function(e){
      $.ajax({
          data: $(this).serialize(), // get the form data
          type: $(this).attr('POST'), // GET or POST
          url: $(this).attr('Private/change_password.php'), // the file to call
          success: function(response) { // on success..
              $('#success_div).html(response); // update the DIV
          },
          error: function(e, x, r) { // on error..
              $('#error_div).html(e); // update the DIV
          }
      });
      e.preventDefault();
  });
  </code></pre>
  
  <p>And then the php:<br></p>
  
  <pre><code>&lt;?php
  $usr = $_SESSION["username"];
  $old_pwd = $_POST["change_password"];
  $new_pwd = $_POST["new_password"];
  
  $link = new PDO('mysql:host=*;dbname=*;charset=UTF-8','*','*');
  $query = "SELECT *
          FROM Conference
          WHERE Username = :un";
  
  $stmt = $link-&gt;prepare($query);
  
  $stmt-&gt;bindParam(':un', $usr);
  $stmt-&gt;execute();
  $row = $stmt-&gt;fetchAll();
  
  $hash = $row[0]["Password"];
  $is_correct = Bcrypt::check($old_pwd, $hash);
  if($is_correct) {
      $query = "UPDATE Conference
              SET `Password`=:new_pwd 
              WHERE Username = :usr";
  
      $stmt = $link-&gt;prepare($query);
      $stmt-&gt;bindParam(':new_pwd', $new_pwd);
      $stmt-&gt;bindParam(':usr', $usr);
      $stmt-&gt;execute();
  }
  </code></pre>
  
  <p>But I'm stuck on a few things.<br>
  1) How do I post the data to change_password.php rather than serialize it so that I can use <code>$_POST</code>?<br>
  2) Does the change_password look correct? It's basically checking what the person entered in for <code>current password</code> with the existing password in the database. And if they match then it changes the password.</p>