成员和管理员的不同重定向

Hope all is well!

I am trying to code my login.php so that it redirects to consumerView.php for a member and admin.php for employee/admin. I have written the following php code but I keep getting redirected to consumerView.php even though the role of the login info is for an employee. Could someone provide any insight to get this working please? The SQL query works, I tested it in phpmyadmin. Disclaimer: I am new to php.

// SELECT query
    $query1 = "SELECT u.id, u.email, u.pass password, r.name role
              FROM users u INNER JOIN role r ON r.id = u.ro_fk
              WHERE email = ? AND u.pass = ? ;";

  if(r.name == 'member'){
  header("Location: consumerView.php");}
  else
  {header("Location: admin.php");}
  die();
} else {
  //If the username/password doesn't matche a user in our database
  // Display an error message and the login form
  echo "Failed to login";
}
} else {
  echo "failed to prepare the SQL";
    }
 }

?>

You have got result in $myrow.

$myrow = $result->fetch_assoc();
//Create a session variable that holds the user's id
$_SESSION['id'] = $myrow['id'];
//Redirect the browser to the profile editing page and kill this page.

if($myrow['name'] == 'member'){  // <- You need to change this line to check user is member or not.
header("Location: consumerView.php");
}
else{
header("Location: admin.php");
}

Replace

if(r.name == 'member')

with

 if($myrow['name'] == 'member')

Ok, just to be precise I will elaborate my comment here:

You have

if (r.name == 'member') {
  header("Location: consumerView.php");
}

First of all, you dont have variable r assigned anywhere. Even if you did, it should be $r in php. Then, you are accesing it's property but in php it is done by -> not by dot. So you should obtain your user from $result, and then do something like (or however it will be stored, var_dump your $result to be sure how is it stored)

if ($user->name === 'member') {
  header("Location: consumerView.php");
}

Or you can access it from $myrow = $result->fetch_assoc() if you want, but then you need to access it like array so probably it would be something like $myrow['name'];