Page 1 of 1

user access levels

Posted: Fri Nov 22, 2002 9:46 pm
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

Posted: Fri Nov 22, 2002 10:53 pm
by mydimension
this ought to work for you:

Code: Select all

list($access) = mysql_fetch_array($result);

thanks

Posted: Sat Nov 23, 2002 8:26 am
by sinus
Hi
thanks mydimension, worked a treat.
bye sinus