I am trying to change my navigation bar depending on whether the user has signed in. Eventually also checking whether the user is an admin or not and having different list items depending on these conditions.
The issue is since my condition is in PHP it doesn't seem to respect the if statement and when the page is loaded both ul are shown.
I have a session start at the top of my page so the value of "loggedin" should be stored.
<header>
<div class="container">
<div class="Logo">
<img src="./images/LogoSmall.png" width="60px" height="60px" alt="Logo">
<h2> Quality Speakers Global </h2>
</div>
<div>
<nav>
<?php
if($_SESSION["loggedin"] == "yes"){
?>
<ul>
<li class="current"><a href="Index.html">Home</a></li>
<li><a href="Register.html">Login/Register</a></li>
<li><a href="Slideshow.html">Products</a></li>
<li><a href="Report.html">Report</a></li>
<li><a href="userpage.php">My Account</a></li>
</ul>
<?php } else{?>
<ul>
<li class="current"><a href="Index.html">Home</a></li>
<li><a href="Register.html">Login/Register</a></li>
<li><a href="Slideshow.html">Products</a></li>
<li><a href="Report.html">Report</a></li>
</ul>
<?php
}
?>
</nav>
</div>
</header>
What i want is to only show the ul depending on the condition
here is my php login code:
<?php
session_start();
$con = mysqli_connect('localhost','root','pass1','accounts');
if(isset($_POST["UsernameLogin"])) {
$Logusername = $_POST['UsernameLogin'];
}
if(isset($_POST["PasswordLogin"])) {
$Logpassword = $_POST['PasswordLogin'];
}
$query = " select * from users where username = '$Logusername' && password = '$Logpassword'";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$num = mysqli_num_rows($result);
if($num == 1) {
$_SESSION["username"] = $Logusername;
$_SESSION["level"] = $row["usertype"];
$_SESSION["loggedin"] = 'yes';
if($_SESSION["level"] == "admin") {
header('location:AccountsPage.php');
} else {
header('location:userpage.php');
}
} else {
header("Location: Index.html");
}
?>