Currently i've got a working database class for MySql interaction, the function that i use is:
That works fine, i often use it to call things like $db->query($sql); and whatnot.Code:function newdb() { //host, username variables etc are defined here but i removed for security $db = new db(); $connection = $db->connect($dbhost, $dbusername, $dbpassword, $db_name); return $db; }
What i'm currently trying to do is check whether a user is logged in, what authorisation level they are and then return a user class that i can then do things with (classes: guest, user extends guest, mod extends user, admin extends user - you get the idea)
The function i'm trying to use to create a new $user dependent on the rank that's stored in the database is:
The session variables are fine (i've checked them) and are set upon login. I've done a little debugging and i've found that without logging in, it appears to set the $user variable but it doesn't seem to like returning it properly.Code:function createuser() { // if the user is logged in, create the user based on rank and set all the details (from the database) as class properties if(isset($_SESSION['logged_in'])) { if($_SESSION['userrank'] == 1) { $user = new user($_SESSION['userid']); $user->setuserdetails(); } elseif($_SESSION['userrank'] == 2) { $user = new moderator($_SESSION['userid']); $user->setuserdetails(); } elseif($_SESSION['userrank'] == 3) { $user = new administrator($_SESSION['userid']); $user->setuserdetails(); } } else { $user = new guest(); } return $user; }
Running this:
Also works as it should (i.e. just before the function returns $user) and echoes out a test message to the browser.Code:else { $user = new guest(); $user->testecho(); }
Simply creating a user in the main page works, and i can call methods fine, it's just when i try to get it from the function it plays up. Am i missing something obvious?


LinkBack URL
About LinkBacks
Reply With Quote


- so of course whenever i tried to call a method it moaned that $user was non-object.
SCAN.care@HEXUS
