0

Im trying to write a function to update password with codeigniter and here is the code

public function changepass(){
    $password = md5( $this->_clean($_POST['Password']) );
    $data = array(
       'Password' => $password
    );        
    $this->db->update('users', $data, array('UserName' => $_POST[UserName]));
} 

this updates the database but still throwing a message

Severity: Notice
Message: Use of undefined constant UserName - assumed 'UserName'

how to prevent this message and also how to check whether query executes successfully or not and echo a message "success" in this case?

1
  • I might be missing something, but do you validate if $_POST['UserName'] is the username of the current user? If not, what stops me from posting your username with password of my choice and then log in into your account? IMHO you should not use $_GET/$_POST in such scenario at all - you should obtain the user to update from the session. Commented Aug 22, 2011 at 12:55

1 Answer 1

5

Change $_POST[UserName] to $this->input->post('UserName') as long as you are in controller. This does not work in model. CodeIgniter also destroys $_POST array.

$this->db->affected_rows() should return 1 for success.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, i tried $this->db->affected_rows(), if the user type same pass as before this returns 0. that means query not executed?
I guess it is executed but nothing changes, means affecting 0 rows. I suggest you using ids instead of strings to identify users data as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.