I'm trying to make a function that checks the user level.
function run_admin($userid, $username){
global $dbcon;
$stmt = $dbcon->prepare("SELECT userid, username, admin FROM user WHERE userid = ?");
$stmt->bind_param('isi',$userid, $username, $admin);
$userid = $_SESSION['userID'];
$stmt->execute();
$stmt->bind_result($userid,$username,$admin);
$stmt->fetch();
//if($admin >= 1){ echo $userid . " is admin!"; }
// above prints "1 is admin!";
}
if(run_admin("1", "Mikkel") == "1")){
echo "It's working, you are admin";
}
I've included the file with the $dbcon and it is working on another page. The global is a idea from another question, mysqli/mysql query inside function not working but I can't get it working.
I'd like to use the function to check if session logged in userID and username .
The admin row returns with integers.
I'm not really good at mysqli prepared statements, still learning but this I don't know where to read about.
Could anyone help or guide me in the right direction.