Isaac
asked on
PHP error undefined index
Can somebody take a look at my code and see what I'm doing wrong?
I'm trying to create a login page and when I call the funtion "checkLogin()" it bombs on me.
It's supposed to check what level of access the user has.
Below are the roles.
1=> SYS ADMIN(everything plus DELETE), \
2=>ADMIN(edit,view,update)
3=>ANALYST(view only)
I have an edit page that calls the function like this:
checkLogin('1 2 3')
I'm trying to create a login page and when I call the funtion "checkLogin()" it bombs on me.
It's supposed to check what level of access the user has.
Below are the roles.
1=> SYS ADMIN(everything plus DELETE), \
2=>ADMIN(edit,view,update)
3=>ANALYST(view only)
I have an edit page that calls the function like this:
checkLogin('1 2 3')
//----- functions.php -----
<?php
#require_once('db.php');
//LEVEL ACCESS
//1=> SYS ADMIN(everything plus DELETE), 2=>ADMIN(edit,view,update) 3=>ANALYST(view only)
echo("sorry");
function checkLogin($role)
{
echo $role;
exit;
if(!$_SESSION['logged_in'])
{
$access = FALSE;
}
else {
$kt = split(' ', $role);
$query = mysql_query('SELECT level_access FROM tblUsers WHERE ID = "'. mysql_real_escape_string($_SESSION['user_id']).'"');
$row = mysql_fetch_assoc($query);
$access = FALSE;
while(list($key,$val)=each($kt)) <-- ERROR LINE
{
if($val==$row['LEVEL_access'])
{//if the user level matches one of the allowed levels
$access = TRUE;
}
}
}
if($access==FALSE)
{
header("Location: login.php");
}
else {
//do nothing: continue
}
}
?>
ASKER
Please ignore lines 10 and 11. That was just for debugging purposes.
Here's the error I get
Notice: Undefined index: LEVEL_access in /home/serveinc/serveinc.or g/docs/adm in/functio ns.php on line 52
Notice: Undefined index: LEVEL_access in /home/serveinc/serveinc.or g/docs/adm in/functio ns.php on line 52
Notice: Undefined index: LEVEL_access in /home/serveinc/serveinc.or g/docs/adm in/functio ns.php on line 52
Warning: Cannot modify header information - headers already sent by (output started at /home/serveinc/serveinc.or g/docs/adm in/functio ns.php:52) in /home/serveinc/serveinc.or g/docs/adm in/functio ns.php on line 60
Line 52 refers to the While Loop and Line 60 is 'header("Location: login.php");'
Here's the error I get
Notice: Undefined index: LEVEL_access in /home/serveinc/serveinc.or
Notice: Undefined index: LEVEL_access in /home/serveinc/serveinc.or
Notice: Undefined index: LEVEL_access in /home/serveinc/serveinc.or
Warning: Cannot modify header information - headers already sent by (output started at /home/serveinc/serveinc.or
Line 52 refers to the While Loop and Line 60 is 'header("Location: login.php");'
Add these lines at the top of the page..
<?php
ob_start();
session_start();
?>
Make sure these are the first lines on the page..
neeraj523
<?php
ob_start();
session_start();
?>
Make sure these are the first lines on the page..
neeraj523
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
exit;
so none of the code below that will be executed.