Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to get admin_level of logged in user!? Reply To: How to get admin_level of logged in user!?

#242543
cscodismith
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();