Page 1 of 1
Code dies but no error message
Posted: Sun May 09, 2010 4:18 pm
by me!
Thus is not working, I can't see any errors in it but line 4 caused it to die. But no error is given?
Code: Select all
// now look up this users permissions for this group
$query = "SELECT * FROM permissions WHERE username='$username' AND group_id ='$group_id'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
// set the user permissions
$_SESSION["permission"] = $row['access_levell'];
Re: Code dies but no error message
Posted: Sun May 09, 2010 4:26 pm
by BKiddo
Hi me!
A couple of things..
You don't need the or die(mysql_error()); twice - which might be why you're not getting an error.
Code: Select all
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
Should work fine, I think.
Code: Select all
// set the user permissions
$_SESSION["permission"] = $row['access_levell'];
^the code above could also be causing problems. I don't think you can set a global variable like that, what are you trying to do here?
Re: Code dies but no error message
Posted: Sun May 09, 2010 4:46 pm
by me!
Removed the second or die and the code runs til the end, but does not do what I want it to.
This is what I am looking for:
Code: Select all
// now look up this users permissions for this group
// get the users permission level from the permissions table where the user name = X and the group_id = Y
$query = "SELECT * FROM permissions WHERE username='$username' AND group_id ='$group_id'";
// get it...
$result = mysql_query($query) or die(mysql_error());
// get the info from the row
$row = mysql_fetch_array($result);
// take what in in the DB for access_level and register it to $_SESSION["permission"] for future use
$_SESSION["permission"] = $row['access_levell'];
Re: Code dies but no error message
Posted: Sun May 09, 2010 4:55 pm
by BKiddo
I'd do a quick test then to make sure that the row is definitely being pulled from the database.
Do this by print_r($row); if you get the array printed out then you know the mysql is working fine.
If the mysql is working then how about checking these things:
1) Is the row column in the pemissions table definitely called access_levell? I'm asking as it looks like it has 2 L's or is that a number 1?
2) $_SESSION["permission"] <-- you're using " there instead of '. Not sure if that makes a difference though.
Re: Code dies but no error message
Posted: Sun May 09, 2010 5:06 pm
by me!
I thought you found it with the two L's, that was an error but not all of it.
I changed the " to ' But I don't thing that does anaything in this case since others are working.
I print_r($row); and get nothing...
Checked, table name and column name they are good...
Re: Code dies but no error message
Posted: Sun May 09, 2010 5:27 pm
by me!
FOUND IT!
When you are asking form data in the db that matches $username and $group_id you want to make sure there is a user with the proper group_id !!!!!!!!
I just spent the last 1.5 hours pulling my hair out on this!

Re: Code dies but no error message
Posted: Sun May 09, 2010 5:47 pm
by me!
This was the final result, Thanks
Code: Select all
// now look up this users permissions for this group
$query = "SELECT * FROM permissions WHERE username='$username' AND group_id ='$group_id'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
if(mysql_num_rows($result)!='0'){ // If match.
$_SESSION['permission'] = $row['access_level'];// set the user permissions
$_SESSION['username'] = "$username"; // Craete session username.
$_SESSION['group_id'] = "$group_id"; // set the group_id
}else{
$message.="<div class=\"errorbox\">You do not have any access rights to this group</div>";
}
Re: Code dies but no error message
Posted: Sun May 09, 2010 6:05 pm
by BKiddo
Glad you got it sorted!