I am struggling to get my login system to work for a college project.
i have a signUp.php page with two roles to choose from "librarian" and "Member".
Depending on the role they chose. when they sign in they will see a different "home.php" page.
I think the issue is the if statement on the home page or the way i have structured the "UserRole" section on the sign Up page. my page keeps showing "Librarian" Content no matter what role i choose. Still new here, i cant pinpoint what i have done wrong.
home.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Only-Books</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<?php
if(isset($_SESSION['UserRole']) == 'Librarian'){
// header ("Location: home.php");
include ('Librarian.php');
} else if(isset($_SESSION['UserRole']) == 'Member' ) {
// header ("Location: home.php");
include ('Member.php');
} else {
header ('Location: signIn.php');
}
?>
signUp.php
<form method="POST" action="process.php" >
<input id="UserName" type="text" name="UserName" placeholder="Your Name" required>
<input id="UserSurname" type="text" name="UserSurname" placeholder="Your Surname" required>
<input id="UserEmail" type="text" name="UserEmail" placeholder="Your Email" required>
<br>
<!-- add a radio for librarian or member -->
<p>Are you a librarian?</p>
<input id="UserRole" type="radio" name="Librarian" value="Librarian" required>
<p>Or a Member?</p>
<br>
<input id="UserRole" type="radio" name="Member" value="Member" required>
<input id="UserPassword" type="password" name="UserPassword" placeholder="Your Password" required>
<input id="UserPassword2" type="password" name="UserPassword2" placeholder="Confirm Password" required>
<input type="submit" name="submit" value="Sign Up">
process.php "signUp procssor"
<?php
session_start();
include_once ('database.php');
if(isset($_POST['submit'])){
$UserName = $_POST['UserName'];
$UserSurname = $_POST['UserSurname'];
$UserEmail = $_POST['UserEmail'];
$UserType = $_POST['UserRole'];
$UserPassword = $_POST['UserPassword'];
$sql = "INSERT INTO users (UserName, UserSurname, UserEmail, UserRole, password) VALUES ('$UserName', '$UserSurname', '$UserEmail', '$UserType', '$UserPassword')";
if(mysqli_query($conn, $sql)){
header ("Location: signIn.php");
} else {
echo "Something Is Broken";
}
mysqli_close($conn);
}
if(isset($_POST['submit'])){
$_SESSION['UserName'] = $_POST['UserName'];
$_SESSION['UserSurname'] = $_POST['UserSurname'];
$_SESSION['UserEmail'] = $_POST['UserEmail'];
$_SESSION['UserRole'] = $_POST['UserRole'];
$_SESSION['UserPassword'] = $_POST['UserPassword'];
}
?>
signIn Processor
<?php
session_start();
if(isset($_POST['login'])){
extract($_POST);
include ('database.php');
$sql = "SELECT * FROM users WHERE UserEmail = '$UserEmail' AND password = '$UserPassword'";
$row = mysqli_fetch_array(mysqli_query($conn,$sql));
if(is_array($row)){
$_SESSION['ID'] = $row['UserID'];
$_SESSION['UserEmail'] = $row['UserEmail'];
$_SESSION['UserPassword'] = $row['password'];
$_SESSION['UserName'] = $row['UserName'];
$_SESSION['UserRole'] = $row['UserRole'];
$_SESSION['UserSurname'] = $row['UserSurname'];
header('location:home.php');
} else {
echo "Login Failed";
}
}
?>