CodeIgniter Forums
[URGENT HELP]Severity: Notice Message: Undefined variable:user_id Filename: controllers/users.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [URGENT HELP]Severity: Notice Message: Undefined variable:user_id Filename: controllers/users.php (/showthread.php?tid=37099)



[URGENT HELP]Severity: Notice Message: Undefined variable:user_id Filename: controllers/users.php - El Forum - 12-27-2010

[eluser]chazy (aldever calvo)[/eluser]
hi.. i can't fix on what's happening on my CRUD in edit... this is my code it also says that i got error in line 63 and 65...

Quote:A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Users::edit()

Filename: controllers/users.php

Line Number: 63

this is my code:

63: function edit($user_id)
64: {
65: $data['id'] = $this->user_model->GetUser(array('user_id' => $user_id));
66: if (!$data['id']) redirect('users');
67: }


[URGENT HELP]Severity: Notice Message: Undefined variable:user_id Filename: controllers/users.php - El Forum - 12-27-2010

[eluser]Twisted1919[/eluser]
That's a common mistake .
Your method is like
Code:
function edit($user_id)
{
//blah blah blah
}
But this means we are forced to provide an user id in the url , something like /user/edit/1 but if we don't provide that 1 and the url is /url/edit that of course, the $user_id var is undefined.
You need to correct this like :
Code:
function edit($user_id='')
{
   if(empty($user_id) || !is_numeric($user_id) || $user_id < 1)
   {
      redirect('users');
   }
   //continue processing because from now on we really have a valid $user_id.

}