if(isset($_SESSION['admin'])) {
echo "<li><b>Admin</b></li>";
}
<?php
session_name('MYSESSION');
session_set_cookie_params(0, '/~cgreenheld/');
session_start();
$conn = blah blah
$query2 = 'Select Type from User WHERE Username = "'.$_SESSION['user'].'" AND Type =\'Admin\'';
$result2 = $conn->query($query2);
if($result2->num_rows==1) {
$_SESSION['admin'] = $result2;
}
?>
Hi, I’m trying to set this session variable but it doesn’t seem to be setting, and i’m wondering if anyone can help. If session[‘admin’] isset it should echo the admin button.
But i’m not quite sure why? (I do have session start and everything on everypage, it’s not a problem with that or any of the “You don’t have php tags” I have checked the mysql query, and it does return something from my table. Any ideas please?
Your
session_start();should be at the top of the page before anything to do with the session variables.From the docs:
When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.
Edit from comments:
Edit 2 from further comments:
You have to actually fetch the fetch the data like this – snipped from this tutorial which might help you out some more:
But having said that, while we are talking about it, you would be better off moving away from the old
mysql_*functions and move to PDO which is much better.