Welcome Guest, Not a member yet? Register   Sign In
Error update
#1

[eluser]ninjayan[/eluser]
Hi everyone!
I currently have this code

controller
Code:
$this->form_validation->set_rules('old_password', 'Password', 'required|trim|min_length[4]|max_length[32]');
    $this->form_validation->set_rules('new_password', 'Password', 'required|trim|min_length[4]|max_length[32]');
    $this->form_validation->set_rules('retype_password', 'Password', 'required|trim|min_length[4]|max_length[32]|matches[new_password]');

    if ($this->form_validation->run() == FALSE)
    {
     $password_result['errors'] = validation_errors();
    }
    else
    {
     //PROCEED UPDATING PASSWORD
     $this->load->model('user_update');

     if ($this->user_update->password())
     {
      $password_result['success'] = true;
     }
     else
     {
      $password_result['errors'] = "<p>Unable to update your Password.</p>";
     }
    }

and this
model
Code:
public function password()
{
  $old_password = md5($this->input->post('old_password'));
  $new_password = md5($this->input->post('new_password'));

  //CHECK FIRST IF THE OLD PASSWORD SUBMITTED IS CORRECT
  $this->db->select('password');
  $this->db->from('users');
  $this->db->where('username', $this->session->userdata('username'));
  $this->db->where('password', $old_password);
  $query = $this->db->get();

  if ($query->num_rows() == 1)
  {
   //UPDATE THE PASSWORD
   $data = array('password', $new_password);
   $this->db->where('username', $this->session->userdata('username'));
   $update_query = $this->db->update('users', $data);

   if ($update_query)
   {
    return true;
   }
   else
   {
    return false;
   }
  }
  else
  {
   return false;
  }
}

When I remove the lines
Code:
//UPDATE THE PASSWORD
   $data = array('password', $new_password);
   $this->db->where('username', $this->session->userdata('username'));
   $update_query = $this->db->update('users', $data);

   if ($update_query)
   {
    return true;
   }
   else
   {
    return false;
   }
from the model, it works fine

but when I added the active record for updating, this error message shows at the console.

Code:
http://localhost/dts/site/update_password 500 (Internal Server Error)

Need help over here.




Theme © iAndrew 2016 - Forum software by © MyBB