Reputation: 147
I have the following code which I have been trying to modify for use with two users (bottom half).
What I want to happen is that when a user logs in , their Login_ID is found in the table and then their User_Role_ID is found.
If its 1 it goes to a certain page , if its 2 it goes to another page.
if(count($_POST)>0) {
$result = mysqli_query($conn, "SELECT id,Login_ID,Name,User_Role_ID FROM user WHERE Login_ID='" . $_POST["id"] . "' ");
$row = mysqli_fetch_array($result);
if(is_array($row)) {
$_SESSION["Login_ID"] = $row[Login_ID];
}
else {
echo "Invalid ID!";
}
}
if($_SESSION["User_Role_ID"] == "2") {
header("Location: home.php");
}
else if($_SESSION['User_Role_ID'] == 1) {
header("Location: www.google.com");
}
Upvotes: 0
Views: 80
Reputation: 62
Maybe you could use a switch
$result = mysqli_query($conn, "SELECT id,Login_ID,Name,User_ID_Role FROM user WHERE Login_ID='" . $_POST["id"] . "' ");
$row = mysqli_fetch_array($result);
if(is_array($row)) {
$_SESSION["Login_ID"] = $row[Login_ID];
switch ($row["User_ID_Role"]){
case "1": header("Location: www.google.com"); break;
case "2": header("Location: home.php"); break;
}
}
else {
echo "Invalid ID!";
}
Upvotes: 1
Reputation: 1637
You must defined $_SESSION["User_Role_ID"] and you have an error
$_SESSION["Login_ID"] = $row[Login_ID]
your code must be:
if(is_array($row)) {
$_SESSION["Login_ID"] = $row["Login_ID"];
$_SESSION["User_Role_ID"]=$row["User_Role_ID"];
}
Upvotes: 0