• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Active Record gotcha

#1
[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.


Messages In This Thread
Active Record gotcha - by El Forum - 10-22-2007, 09:13 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.