user access levels

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sinus
Forum Newbie
Posts: 10
Joined: Fri Nov 22, 2002 9:46 pm

user access levels

Post by sinus »

Hi,
I'm trying to setup a login script that checks a username and password, then selects an admin level from may database for that user, then process the admin level into a switch statement.
i have checked that the username and password are correct.
mysql query executes.
but i'm having trouble assigning the admin level abstracted from the database to a variable for the switch statment.

sample code

// query and return result
$query = "SELECT level FROM admin WHERE loginname='$loginname' AND loginpassword='$loginpassword'";
$result = mysql_db_query ($databasename, $query, $connection);

//heres where i have the problem, how to i pass the value of 'level'
// abstracted from the database to the variable $access for the
//switch statment to process.


switch ($access) {
case "all":
print ("Access all areas");
break;

case "level1":
print ("You can only access level 1");
break;

default:
print ("Error at login contact admin");
}


Any help would be greatly appreciated.

Thanks Sinus
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

this ought to work for you:

Code: Select all

list($access) = mysql_fetch_array($result);
sinus
Forum Newbie
Posts: 10
Joined: Fri Nov 22, 2002 9:46 pm

thanks

Post by sinus »

Hi
thanks mydimension, worked a treat.
bye sinus
Post Reply