I have this code
session_start();
$username = $_SESSION['username'];
function getUserRole($username, $roleid){
$con=dbConnect();
$query="select * from user inner join userrole on user.id = userrole.userid inner join role on role.id = userrole.roleid where username = $username";
$sql=$con->prepare($query);
$sql->bindValue(':username',$username);
$sql->bindValue(':roleid',$roleid);
$sql->execute();
$row = $sql->fetch();
$username = $row['username'];
$roleid = $row['roleid'];
if($row > 0){
return $username;
}
else{
return false;
}
}
My pain is that when i query the database where the username = $username, the query returns nothing but when i use the text for username i get results. Do session variables work inside functions? What can i be possibly be doing wrong?