I couldn't find any simple example on how to use data from MySQL DB in a PHP variable... I'm trying to validate an specific type of user.. I want users with ID_Perfil = 001 to be redirected to "MenuExamenes.php" and users with ID_Perfil= 002 to be redirected to "MenuPrincipal.php.". Just trying to learn the basics. I now this is the least optimal way to do this..
I have my config.php file:
<?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);
?>
Then I have my loging.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";
}
}
?>
Aucun commentaire:
Enregistrer un commentaire