I am currently doing a php to make a login and redirect users, if the login matches and appears, then go to check if it is admin or not, for this, the query should return in the select the role, the doubt is, how do I get the role out and then compare it with an if?
<?php
//Login en la base de datos
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
//Coge las variables del ajax
$email = $_POST["email"];
$contraseña = $_POST['password'];
// Crea una nueva conexion
$conn = new mysqli($servername, $username, $password, $dbname);
// Comprueba la conexion
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$total = mysqli_num_rows(mysqli_query($conn," SELECT email FROM USUARIOS where email = '$email' and password = '$contraseña'"));
if($total == 1){
$admin = $conn,"SELECT role FROM USUARIOS where email = '$email' and password = '$contraseña'" ->get_result() ;
if( $admin == 'admin'){
echo "U are a admin user" . $admin;
header('Location: ../admin.html');
} else {
echo "U are a normal user" . $admin;
header('Location: ../user.html');
}
}else{
echo "Error login";
}
$conn->close();
?>
At the moment it is what I have done (I accept modifications or explanations also of other things since I am doing it as I can)