Stack Overflow Asked by GymPotato on December 5, 2020
I am very new to php and HTML, I need to create a page after a user log-in to show a menu for a different type of user.
1st user = employer
2nd user = job seeker
The menu for job seekers should display at least the following options:
Menu
Edit Profile
Application History
Search Jobs
View Jobs by Category
View Jobs by Company
Log Out
The menu for employers should display at least the following options:
Menu
Edit Company Profile
Post a new Position
Edit/Delete a Posted Position
Review Applications for a position
Search Applicants
Log Out
I was able to fix my code and login with two different types of users.
The only problem now is that my second user – employer, won’t show the css style that I have created. Everything is working fine in the jobseeker menu.
<!DOCTYPE html>
<?php
session_start();
if (!isset($_SESSION['usertype'])){
Header('Location:login.php?msg=Hacker');
}
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
background-image:
url('background.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
margin:0;
font-family:Lucida Sans Unicode, Lucida Grande, sans-serif;
}
.topnav {
background-color: #333;
overflow: hidden;
}
.topnav a{
float: left;
color: #c7e1db;
text-align: center;
padding: 18px 70px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover{
background-color: #ddd;
color: #1d77dd;
}
.topnav a.active{
background-color: #ec5e5e;
color: white;
}
</style>
</head>
<body>
<center>
<?php
if($_SESSION['usertype'] == 'JobSeeker') {
?>
<div class="topnav">
<a class="active" href="http://localhost/a2/menu.php">Menu</a>
<a href="profile.php"> Profile</a>
<a href="#appHist">History</a>
<a href="#jobCat">View Jobs by Category</a>
<a href="#jobCom">View Jobs by Company</a>
<a href="logout.php"> Not <?php echo $_SESSION['username'] ?>? Logout Here</a>
</div>
<br>
<?php } //for employer
elseif($_SESSION['usertype'] == 'employer') {
?>
<a class="active" href="menu.php">Menu</a>
<a href="#profile">Edit Profile</a>
<a href="#appHist">Application History</a>
<a href="#jobCat">View Jobs by Category</a>
<a href="#jobCom">View Jobs by Company</a>
<a href="logout.php"> Not <?php echo $_SESSION['username'] ?> ? Logout Here</a>
</div>
<br>
<br>
<?php
echo 'Welcome ' . $_SESSION['username'];
?>
<?php } ?>
</center>
</body>
</html>
Your code should work, there has some problem in taking sessions that's why it wasn't working. You can do one thing when registering you can take usertype
in your database. Suppose I am registering as a job seeker, then you can take usertype
as a jobseeker
value otherwise the usertype
value will be employer
.
When a user logged in obviously you are taking a session for login with username and password.
So after login, you have username, Easily you can get that specific username's usertype
.
Then you can do an if else condition.
Suppose when a user loggedin you have take that user's username session is
$admin = $_SESSION['username'];
then fetch the usertype of that $admin
The query should be like this
$fetch_usertype = mysqli_fetch_assoc(mysqli_query($con,"SELECT * FROM 'ypor_user_table' WHERE 'username_column' = '$admin'"));
$usertype = $fetch_usertype['user_type_column'];
Now you have usertype
, so you can go for an if else condition.
<?php if ($usertype == 'employer') {?>
<ul>
<li><a class="active" href="menu.php">Menu</a></li>
<li><a href="#application.php">Edit Profile</a></li>
<li><a href="#appHist">Application History</a></li>
<li><a href="#jobCat">View Jobs by Category</a></li>
<li><a href="#jobCom">View Jobs by Company</a></li>
<li style="float:right"><a class="active" href="#user">
<ul> <?php; }
elseif ($usertype == 'JobSeeker') { ?>
<ul>
<li><a class="active" href="#menu">Menu</a></li>
<li><a href="#profile">Edit Profile</a></li>
<li><a href="#appHist">Application History</a></li>
<li><a href="#jobCat">View Jobs by Category</a></li>
<li><a href="#jobCom">View Jobs by Company</a></li>
</ul>
<?php } ?>
Answered by Mehedi Hasan Siam on December 5, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP