0

I'm currently trying to redirect a current user type to it's specific site using sessions, whilst also creating a session to check if they are logged in.

The users are all in the same table and have been categorised with either 1, 2 or 3. This is what I have tried so far:

<?php
session_start();
include ('connection/conn.php');


$user = $_POST['userfield'];

$password = $_POST['passfield'];

$readcheck = "SELECT * FROM ovo_users WHERE id = '$user' AND pword = '$password' ";

$result = $conn->query($readcheck);

$numrow = $result->num_rows;

if($numrow > 0){

    while ($row = $result->fetch_assoc()){
        $userid = $row['id'];
        $usertype = $row['user_type'];

        $_SESSION['40212246_user_id'] = $userid;
        $_SESSION['40212246_user_type'] = $usertype;

    } 

    if($usertype = 1){
        header("Location: student/index.php");
    }

    elseif($usertype = 2){
        header("Location: tutor/index.php");
    }

    elseif($usertype = 3){
        header("Location: admin/index.php");
    }

    else {
        header("Location: index.php");
    }

}
?>

When I login I get sent to the student/index page no matter what login.

Natasha
  • 1
  • 1

1 Answers1

0
 if($usertype = 1){
    header("Location: student/index.php");
}

This is an immediate problem that stands out to me which you should correct first, a single equal sign is an assignment operator, you want a double equal or triple equal comparison operator.

Honestly I would use a switch statement here instead:

    switch($type) {
    case 1:
        // goto link 1
        break;

    case 1:
        // goto link 2
        break;

    default:
        // goto link 3
}
Lulceltech
  • 1,524
  • 7
  • 17