Hello I am trying to make it so if a ‘admin’ logs on it shows a button for the admin home page ‘ahome.php’ and if a user logs in it only shows the home button for ‘home.php’. I am currently not getting errors but it isn’t showing any buttons.
My header.php is:
<?php
if ($usertype == 'admin'){
echo '<a href="ahome.php" class=" w3-bar-item w3-button w3-round w3-mobile w3-russo"><h4><i class="fa fa-home"></i> HOME</h4></a>';
} else {
echo '<a href="home.php" class=" w3-bar-item w3-button w3-round w3-mobile w3-russo"><h4><i class="fa fa-home"></i> HOME</h4></a>';
}
?>
And the code to pull from the login form is:
$usertype = $_SESSION[‘user_type’];
This is how I think I am pulling the ‘user_type’ from my login in function :
$query = “SELECT * FROM users WHERE username = ‘$username’ AND password = ‘$password’ LIMIT 1”;
$results = mysqli_query($conn, $query);if (mysqli_num_rows($results) == 1) { // Admin Check $logged_in_user = mysqli_fetch_assoc($results); if ($logged_in_user['user_type'] == 'admin') { $_SESSION['user'] = $logged_in_user; $_SESSION['username'] = $username; $_SESSION['user_type'] = $usertype; $_SESSION['success'] = "You are now logged in"; header('location: ahome.php'); }else{ $_SESSION['user'] = $logged_in_user; $_SESSION['username'] = $username; $_SESSION['user_type'] = $usertype; $_SESSION['success'] = "You are now logged in"; header('location: home.php'); } }
my ‘username’ is functioning and at one point I echoed the ‘$usertype’ in the header and it would give me the correct user type. I am just not sure what I am doing wrong i have spent 2 or 3 hours trying to figure this out. Any help would be amazing.