title: change password function
body: <p>I have put together the follow code. But for some reason it refuses to update the database, and it keeps echoing the $error "Your current password is incorrect" no matter what is inputted.</p>
  
  <p>Below is the main changepassword.php</p>
  
  <pre><code>    &lt;?php 
  include 'core/init.php';  //connection to database and checks user sessions
  protect_page(); //useres not loged in cannot access this page
  
  if (empty($_POST) === false) {
      $required_fields = array('current_password', 'password', 'password_again');
      foreach($_POST as $key=&gt;$value) {
          if (empty($value) &amp;&amp; in_array($key, $required_fields) === true) {
              $errors[] = 'All fields marked with an * are required.'; //check that all fields are completed
              break 1;
          }
      }
  
      if (md5($_POST['current_password']) === $user_data['password']) { //if equal to current password
          if (trim($_POST['password']) !== trim($_POST['password_again'])) {
              $errors[] = 'Your new passwords do not match';
          } else if (strlen($_POST['password']) &lt; 6) {
              $errors[] = 'Your password must be at least 6 characters';
          }
      } else {
          $errors[] = 'Your current password is incorrect';   //else append error
      }
  }
  
  include 'includes/overall/header.php'; 
  ?&gt;
  
  &lt;h1&gt;Change Password&lt;/h1&gt;
  &lt;p&gt;Change your account password here.&lt;/p&gt;
  
  &lt;?php
  if (isset($_GET['success']) &amp;&amp; empty($_GET['success'])) {
      echo 'Your password has been changed';
  } else {
  
      if (empty($_POST) === false &amp;&amp; empty($errors) === true) {
          change_password($session_user_id, $_POST['password']);
          header('Location: changepassword.php?success');
      } else if (empty($errors) === false) {
          echo output_errors($errors);
      }
      ?&gt;
  
      &lt;form action="" method="post"&gt;
  
          &lt;ul&gt;
          &lt;li&gt;
              Current Password*:&lt;br&gt;
              &lt;input type="password" name"current_password"&gt;
          &lt;/li&gt;
          &lt;li&gt;
              New Password*:&lt;br&gt;
              &lt;input type="password" name"password"&gt;
  
          &lt;/li&gt;
          &lt;li&gt;
              New Password Again*:&lt;br&gt;
              &lt;input type="password" name"password_again"&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;input type="submit" name="Change Password" /&gt;
          &lt;/li&gt;
          &lt;/ul&gt;
  
      &lt;/form&gt;
  
  &lt;?php 
  }
  include 'includes/overall/footer.php'; ?&gt;
  </code></pre>
  
  <p>Here is the changepassword function</p>
  
  <pre><code>//change password function
  function change_password($membersID, $password) {
      $membersID = (int)$membersID;
      $password = md5($password);
      //update password in database
      mysql_query("UPDATE`members` SET`password` = '$password' WHERE`membersID` = $membersID");   
  }
  </code></pre>
  
  <p>user_data is declared here</p>
  
  <pre><code>//user data variable to pass in sessionID and thus pass in their other details
  if (logged_in() === true) {
      $session_user_id = $_SESSION['membersID']; //picking up the particular user
      $user_data = user_data($session_user_id, 'membersID', 'username','password', 'forename', 'surename', 'email', 'age'); //picks up the fields declared here - MAKE SURE TO PASS ALL paramameters you need to output.
      if (user_active($user_data['username']) === false) {
          session_destroy();
          header('Location: index.php');
          exit();
      }
  
  }
  </code></pre>