Evolver Posted August 25, 2008 Share Posted August 25, 2008 Hello, MySQL 4.1 / PHP 5.2 I'm a newbie to MySQL and novice to PHP. I've managed to setup my site to authenticate users: function login($username, $password) // check username and password with db // if yes, return true // else throw exception { // connect to db $conn = db_connect(); // check if username is unique $result = $conn->query("select * from user where username='$username' and password = sha1('$password')"); if (!$result) throw new Exception('Could not log you in.'); if ($result->num_rows>0) return true; else throw new Exception('Could not log you in.'); } I've added a column to the database in user called permission. I have 2 settings for permission, 1 for admin and 2 for all other users. I simply want to be able to redirect the user after login to either the admin section or the member section. Does anyone have any suggestions on how i can do this? I attempted to create a php variable called $permission based on the user's permission setting in MySQL but alas this is where my newbiness is shining. Here is what i came up with: function findPerm($username, $password) { //extract from the database the permission this user has stored $conn = db_connect(); $result = $conn->query( "select permission from user where username = '$username' and password = sha1('$password')"); if (!$result) return false; $row = $result->fetch_row(); return $row['permission']; } This didn't work when i tried to use the following code to display the permission setting after login: findPerm(); echo $permission; (In retrospect perhaps i can just assign a permission to admin and NULL to members so i won't have to worry about inserting anything for them later. This is just what i have come up with so far, i'm open to suggestions!) Any help would be appreciated! Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.