Home › Forums › Back End › How to get admin_level of logged in user!? › Reply To: How to get admin_level of logged in user!?
June 6, 2016 at 4:25 am
#242543
Participant
My current code looks quite similar to look this now. My working live code now looks like the following where it selects the session’s username to capture the admin_level from the current logged in users column:
$connStr = 'mysql:host=localhost;dbname=heartfx-registration';
$user = 'root';
$pass = '';
// only use $dbuser if logged in:
if (isset($_SESSION['username'])) {
$dbuser = $_SESSION['username'];
}
// Create the connection object
$conn = new PDO($connStr, $user, $pass);
$sth = $conn->prepare("SELECT admin_level FROM users WHERE username = :username");
$sth->bindParam(':username', $dbuser);
$sth->execute();
$result = $sth->fetchColumn();