I am trying to use a function to return a simple value from a database, while this is usually easy, I am having some difficulty. I have tried several different mixtures with no success so I have decided to turn to this community for help.
The concept is a database structure has ranks with pagetypes that are assigned permissions.
Current columns for this example: rank / modreports / plreports
Data Example: admin / 1 / 1
function CheckPermission($module){
$GetPerms = mysql_query("SELECT * FROM `permissions` WHERE `rank` = '".$MyDetails['group']."' LIMIT 1");
$MyPerm = mysql_fetch_array($GetPerms);
if($MyPerm[$module] != 1){
echo 'DEBUG: '.$MyPerm[$module];
//redirect("index.php?resp=perms");
die();
}
}
Usage Example:
CheckPermissions(modreports);
The above usage should return DEBUG: 1 at this stage OR show nothing at all (preferably the second one), instead it shows DEBUG:. $MyPerm['modreports'] will return the correct value so I assume it to be the variable within the variable which I have only used in $_POST[''] in the past.
Thanks for your help, I hope I have provided enough information to get some help.
In response to the assistance, this is the corrected code;
function CheckPermission($module,$group){
$GetPerms = mysql_query("SELECT * FROM `permissions` WHERE `rank` = '".$group."' LIMIT 1");
$MyPerm = mysql_fetch_array($GetPerms);
if($MyPerm[$module] != 1){
redirect("index.php?resp=perms");
die();
}
}
var_dumping that variable. again your problem will become obvious. Finally, if you had error reporting turned on with all levels, you would get a notice here that would also point you to the problem. So in summary, your biggest issue is that you need to really focus on learning how handle to debug your code, handle edge/error cases, and always keep an eye on your error messaging when developing.