CodeIgniter Forums
Active Record gotcha - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active Record gotcha (/showthread.php?tid=3794)



Active Record gotcha - El Forum - 10-22-2007

[eluser]Michael Ekoka[/eluser]
in the following code I want to update the password field in one record :

Code:
$form_data = $this->input->post('form_data');

// I get my input from a form
$user_id = $form_data['user_id'];
$password = md5($form_data['password']);

$this->db->where('id',$id);
// notice the mistake I just made: instead of $user_id, I used $id that has not yet been
// initialized or declared.

$this->db->update('users',array('password'=>$password));

What I will end up doing here is update the password field of all records in the table. So, fellow CodeIgniters beware when making update and delete operations like these.