title: To retrieve the forgot password
body: <p>In the below code i have used codeigniter code i enter username and password to db.but i want to retrieve my forgot password .I tried but i got the following errors pls help to recify the issue.</p>
  
  <p>Controller:</p>
  
  <pre><code>&lt;?php
  
  class Login extends CI_Controller {
  
      function index()
      {
          $data['main_content'] = 'login_form';
          $this-&gt;load-&gt;view('includes/template', $data);      
      }
  
      function validate_credentials()
      {       
          $this-&gt;load-&gt;model('membership_model');
          $query = $this-&gt;membership_model-&gt;validate();
  
          if($query) // if the user's credentials validated...
          {
              $data = array(
                  'username' =&gt; $this-&gt;input-&gt;post('username'),
                  'is_logged_in' =&gt; true
              );
              $this-&gt;session-&gt;set_userdata($data);
              redirect('site1/members_area');
          }
          else // incorrect username or password
          {
              $this-&gt;index();
          }
      }   
  
      function signup()
      {
          $data['main_content'] = 'signup_form';
          $this-&gt;load-&gt;view('includes/template', $data);
      }
  
      function create_member()
      {
          $this-&gt;load-&gt;library('form_validation');
  
          // field name, error message, validation rules
          $this-&gt;form_validation-&gt;set_rules('first_name', 'Name', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('last_name', 'Last Name', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('email_address', 'Email Address', 'trim|required|valid_email');
          $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|min_length[4]');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
          $this-&gt;form_validation-&gt;set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
           $this-&gt;load-&gt;helper('date');
  
          if($this-&gt;form_validation-&gt;run() == FALSE)
          {
              $this-&gt;load-&gt;view('signup_form');
          }
  
          else
          {           
              $this-&gt;load-&gt;model('membership_model');
  
              if($query = $this-&gt;membership_model-&gt;create_member())
              {
                  $data['main_content'] = 'signup_successful';
                  $this-&gt;load-&gt;view('includes/template', $data);
              }
              else
              {
                  $this-&gt;load-&gt;view('signup_form');           
              }
          }
  
      }
      public function forgot_password()
  {
      $this-&gt;form_validation-&gt;set_rules('email_address','Email Address','trim|required|valid_email|callback__check_email_exists');
  
      if($this-&gt;form_validation-&gt;run() == FALSE)
      {
         // VALIDATION ERRORS, SHOW VIEWS
         $this-&gt;index();
      }
      else
      {
        // ALL IS GOOD, UPDATE EMAIL, AND REDIRECT TO CURRENT URL
        $this-&gt;load-&gt;view('login_form');
      }
  }
  public function _check_email_exists($email)
  {
    // LOAD AND USE YOUR MODEL TO CHECK EMAIL EXISTS HERE
    if ( ! $email_exists )
    {
      $this-&gt;form_validation-&gt;set_message('email_address', 'That email address don\'t exist, sucka!');
      return FALSE;
    }
    else
    {
      return TRUE;
    }
  }
      function logout()
      {
          $this-&gt;session-&gt;sess_destroy();
          $this-&gt;index();
      }
  
  }
  </code></pre>
  
  <p>model</p>
  
  <pre><code>&lt;?php
  
  class Membership_model extends CI_Model {
  
      function validate()
      {
          $this-&gt;db-&gt;where('username', $this-&gt;input-&gt;post('username'));
          $this-&gt;db-&gt;where('password', md5($this-&gt;input-&gt;post('password')));
          $query = $this-&gt;db-&gt;get('membership');
  
          if($query-&gt;num_rows == 1)
          {
              return true;
          }
  
      }
  
      function create_member()
      {
  
          $new_member_insert_data = array(
              'first_name' =&gt; $this-&gt;input-&gt;post('first_name'),
              'last_name' =&gt; $this-&gt;input-&gt;post('last_name'),
              'email_address' =&gt; $this-&gt;input-&gt;post('email_address'),         
              'username' =&gt; $this-&gt;input-&gt;post('username'),
              'date' =&gt; date('Y-m-d H:i:s', now()),
              'password' =&gt; md5($this-&gt;input-&gt;post('password'))                       
          );
  
          $insert = $this-&gt;db-&gt;insert('membership', $new_member_insert_data);
          if ($this-&gt;db-&gt;_error_number() == 1062)
                  {
                  echo"&lt;script&gt;alert('This value already exists');&lt;/script&gt;";
                  }
                  if ($this-&gt;db-&gt;_error_number() == "")
                  {
                  $this-&gt;session-&gt;set_flashdata('create', 'create');
                  }
  
          return $insert;
      }
  
  
      public function val_forgot_password()
  {
      $this-&gt;db-&gt;where('email_address', $this-&gt;input-&gt;post('email_address'));
      $query = $this-&gt;db-&gt;get($this-&gt;members);
  
      if($query-&gt;num_rows == 1)
      {
          return true;
      }
      else
      {
          return false;
      }
  }
      function curdate() {
      // gets current timestamp
      date_default_timezone_set('Asia/Manila'); // What timezone you want to be the default value for your current date.
      return date('Y-m-d H:i:s');
  }
  }
  </code></pre>
  
  <p>view:login_form</p>
  
  <pre><code>&lt;?php $this-&gt;load-&gt;view('includes/header'); ?&gt;
  &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url();?&gt;css/style1.css"  /&gt;
  &lt;div id="login_form"&gt;
  
      &lt;h1&gt;Login!&lt;/h1&gt;
      &lt;?php 
      echo form_open('login/validate_credentials');
      echo form_input('username', 'Username');
      echo form_password('password', 'Password');
      echo form_submit('submit', 'Login');
      echo anchor('login/signup', 'Create Account');
      echo form_close();
      ?&gt;
  
  &lt;/div&gt;&lt;!-- end login_form--&gt;
  
  
  &lt;?php $this-&gt;load-&gt;view('includes/footer'); ?&gt;
  &lt;?php
  
  echo form_open('login/forgot_password');
  echo "Email Address: " . form_input('email_address', set_value('email_address', ''));
  echo br(2);
  echo form_submit('submit','Send Email');
  echo form_close();
  echo br(1);
  
  echo validation_errors('&lt;p&gt;Error: ');
  
  ?&gt;
  </code></pre>