title: check old password and updating a new password using codeigniter
body: <p>Hi i have this page change password. I want to check the current password that matches into the database. then saving the new password on it. However i got it compared in the old password that checks on the database. Im wondering that when i click the change password button there is a pop up dialog box that says confirm password change, and i dont know where that pop up dialog came from. And also my saveNewPass code will not work. Can someone help me figured this out?. Here is my code below.</p>
  
  <p>My controller</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Change_password extends CI_Controller {
    public function __construct(){
      parent::__construct();
      $this-&gt;load-&gt;library('form_validation');
      $this-&gt;load-&gt;model('users_model', 'um');
      $this-&gt;load-&gt;library('session');
      if(!$this-&gt;session-&gt;userdata('loggedIn')){
        redirect('login');
      }
    }
  
  
  
  
    public function change(){
      $this-&gt;form_validation-&gt;set_rules('old_password', 'Password', 'trim|required|xss_clean');
      $this-&gt;form_validation-&gt;set_rules('newpassword', 'New Password', 'required|matches[re_password]');
      $this-&gt;form_validation-&gt;set_rules('re_password', 'Retype Password', 'required');
      if($this-&gt;form_validation-&gt;run() == FALSE){
         $this-&gt;data['title'] = 'Change Password';
          $sessionData = $this-&gt;session-&gt;userdata('loggedIn');
          $this-&gt;data['id'] = $sessionData['id'];
          $this-&gt;data['username'] = $sessionData['username'];
          $this-&gt;data['type'] = $sessionData['type'];
  
          $this-&gt;load-&gt;view('templates/header', $this-&gt;data);
          $this-&gt;load-&gt;view('pages/change_password');
          $this-&gt;load-&gt;view('templates/footer');
      }else{
        $query = $this-&gt;um-&gt;checkOldPass(sha1($this-&gt;input-&gt;post('old_password')));
        if($query){
          $query = $this-&gt;um-&gt;saveNewPass(sha1($this-&gt;input-&gt;post('newpassword')));
          if($query){
            redirect('change_password');
          }else{
            redirect('change_password');
          }
        }
  
      }
    }
  
    public function index(){
      $this-&gt;data['title'] = 'Change Password';
      $sessionData = $this-&gt;session-&gt;userdata('loggedIn');
      $this-&gt;data['id'] = $sessionData['id'];
      $this-&gt;data['username'] = $sessionData['username'];
      $this-&gt;data['type'] = $sessionData['type'];
  
      $this-&gt;load-&gt;view('templates/header', $this-&gt;data);
      $this-&gt;load-&gt;view('pages/change_password');
      $this-&gt;load-&gt;view('templates/footer');
    }
  }
  </code></pre>
  
  <p>My model</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Users_model extends CI_Model {
  
  
     public function checkOldPass($old_password){
      $this-&gt;db-&gt;where('username', $this-&gt;session-&gt;userdata('username'));
      $query = $this-&gt;db-&gt;get('users');
      $row    = $query-&gt;row();
      echo "Old Password : ".$old_password."&lt;br&gt;";
      echo "From DB : ".$row-&gt;password."&lt;br&gt;";
      die;
  
      if($query-&gt;num_rows &gt; 0){
        $row = $query-&gt;row();
        if($old_password == $row-&gt;password){
          return true;
        }else{
          return false;
        }
      }
    }
  
    public function saveNewPass($new_pass){
      $array = array(
              'password'=&gt;$new_pass
              );
      $this-&gt;db-&gt;where('username', $this-&gt;session-&gt;userdata('username'));
      $query = $this-&gt;db-&gt;update('users');
      if($query){
        return true;
      }else{
        return false;
      }
    }  
  
  
  
  }
  </code></pre>
  
  <p>and my views</p>
  
  <pre><code>&lt;div class="container"&gt;
    &lt;div class="homepage_content"&gt;
      &lt;div&gt;
        &lt;ul class="nav nav-pills"&gt;
          &lt;li&gt;&lt;a href=""&gt;Home&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=""&gt;View Profile&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=""&gt;Edit Profile&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo base_url().'change_password'?&gt;"&gt;Change Password&lt;/a&gt;&lt;/li&gt;
          &lt;?php if($type == "Root"): ?&gt;
          &lt;li&gt;&lt;a href=""&gt;Create New Account&lt;/a&gt;&lt;/li&gt;
          &lt;?php endif; ?&gt;
          &lt;li class="pull-right"&gt;&lt;a class="btn btn-primary" href="&lt;?php echo base_url().'logout'?&gt;"&gt;Logout&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;p&gt;welcome &lt;?php echo $username; ?&gt;&lt;/p&gt;
      &lt;p&gt;Account Type &lt;?php echo $type; ?&gt;&lt;/p&gt;
      &lt;br /&gt;
      &lt;form action="&lt;?php echo base_url().'change_password/change'?&gt;" method="post"&gt;
        &lt;div class="errors"&gt;
          &lt;?php echo validation_errors('&lt;div class="error"&gt;', '&lt;/div&gt;'); ?&gt;
        &lt;/div&gt;
        &lt;p&gt;&lt;input type="password" name="old_password" placeholder="Current Password: " class="form-control"&gt;&lt;/p&gt;&lt;br /&gt;
        &lt;p&gt;&lt;input type="password" name="newpassword" placeholder="New Password: " class="form-control"&gt;&lt;/p&gt;&lt;br /&gt;
        &lt;p&gt;&lt;input type="password" name="re_password" placeholder="Retype New Password: " class="form-control"&gt;&lt;/p&gt;&lt;br /&gt;
        &lt;input type="submit" value="change password" class="btn btn-primary" /&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Any help is muchly appreciated</p>