I need help to understand something basic. I have searched everywhere but the answers have not been simple. I have been trying to validate a specific type of user with ID_Profile = 001 to be redirected to "MenuExamenes.php" and users with ID_Profile = 002 that are redirected to "MenuPrincipal.php." I really do not know if it is possible to do something as simple as storing a single value, obviating that it will store the first value it finds ... or the last one. In this case it is a single value so it is not important.
ID_Profile is in the BD an int (3). (I know that this is the least optimal option to do it, it is for a learning project, not real life).
I have a config.php:
<?php
define('DB_SERVER', 'localhost:8889');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'root');
define('DB_DATABASE', 'ProgramaPruebas');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
And I have my login.php
<?php
include("config.php");
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($db,$_POST['user_nickname']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$sqlusertype = "SELECT ID_Perfil FROM Usuarios WHERE user_nickname = '$myusername' and password = '$mypassword";
$result1 = mysqli_query($sqlusertype, $db);
$sql = "SELECT User_Id FROM Usuarios WHERE user_nickname = '$myusername' and password = '$mypassword'";
$result = mysqli_query($db,$sql);
$count = mysqli_num_rows($result);
if($count == 1 && result1 == 001 ) {
echo '<script type="text/javascript">
alert("Inicio de Sesión Exitoso");
window.location.href="MenuExamenes.php";
</script>';
alert("Inicio de Sesión Exitoso");
}
elseif($count == 1 && result1 == 002 ){
echo '<script type="text/javascript">
alert("Inicio de Sesión Exitoso");
window.location.href="MenuPrincipal.php";
}else{
$error = "El usuario/contraseña son incorrectos";
}
}
?>