CodeIgniter Forums
DB/Query Error - 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: DB/Query Error (/showthread.php?tid=33559)



DB/Query Error - El Forum - 08-31-2010

[eluser]Shujin[/eluser]
Code:
function is_staff()
    {
        $id = $this->ci->session->userdata('userid');
        $query = $this->ci->db->get_where('group_memberships', array('userid' => $id));
        $group = $query->row()->groupid;
        
        if ($group <= 2) {
            return true;
        }
    }

Which seems to give me this error:

Quote:A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: libraries/quickauth.php

Line Number: 184

But I have the exact same code right above (at Line: 173)
but it only detects the error at this line.


DB/Query Error - El Forum - 08-31-2010

[eluser]n0xie[/eluser]
What does this tell you if you put it at the end of your function?
Code:
var_dump($group);



DB/Query Error - El Forum - 08-31-2010

[eluser]Shujin[/eluser]
Ah it tells me NULL...

Although this was working before, so I have no idea what went wrong.


DB/Query Error - El Forum - 08-31-2010

[eluser]Shujin[/eluser]
It seems
Code:
$id = $this->ci->session->userdata('userid');

Returns a boolean rather than the actual "ID", any suggestions on how to get the actual ID from the session?


DB/Query Error - El Forum - 08-31-2010

[eluser]WanWizard[/eluser]
It returns the value stored in the session, or FALSE if that value does not exist.


DB/Query Error - El Forum - 08-31-2010

[eluser]Shujin[/eluser]
Ok, so this is the user_data from phpymadmin:
http://uploadir.com/u/1469aeb4

I don't know why it isn't finding what I want it to, i'm basing my code on what quickauth has used to get the userid in other functions, so I don't know why this isn't working...