Good evening everyone, after searching and searching (they are very much sticking with the code and look at things before asking for help), I resort to my first post on this page, because it is something that is bringing me head.
I am in the last year of the CFGS of DAW, and we are with a login and registration app with MVC, to "play around" with the design pattern, everything works perfect: register, delete, update ..., but , at the time of logging ... there is something that is failing me, and I have tried a thousand ways, I do not know why, I do not get the user that I want to consult (the one that initiates session).
UsersController.php
public function loguear(){
$usuario = new Usuario();
$idUsuario = $_POST['idUsuario']; //es el correo electronico
$pass = $_POST['pass'];
$usuario->setIdUsuario($idUsuario); //seteo el idUsuario
$usuarioQueSolicitaLoguearse = $usuario->getIdUsuario(); //lo recojo
$usuarioEnBaseDeDatos = $usuario->loguearUsuario($usuarioQueSolicitaLoguearse); //consulto a la base de datos el idUsuario introducido por el usuario
if($usuarioQueSolicitaLoguearse == $usuarioEnBaseDeDatos){
echo "TODO OK!!!!!<br>";
echo "USUARIO SOLICITANTE: " .$usuarioQueSolicitaLoguearse."<br>";
echo "USUARIO EXISTENTE BBDD: " .$usuarioEnBaseDeDatos."<br>";
// session_start();
// $_SESSION['usuarioLogueado'] = $usuarioQueSolicitaLoguearse;
// echo $_SESSION['usuarioLogueado'];
// redireccciono al controlador y el metodo logueo
// $this->redirect("Usuarios","logueo");
// $this->redirectWithSession("Usuarios","logueo",$_SESSION['usuarioLogueado']);
}else{
var_dump($usuarioEnBaseDeDatos);
echo "<br>";
var_dump($usuarioQueSolicitaLoguearse);
echo "<br>";
echo "USUARIO NO ENCONTRADO<br>";
echo "USUARIO SOLICITANTE: " .$usuarioQueSolicitaLoguearse."<br>";
echo "USUARIO EXISTENTE BBDD: ".$usuarioEnBaseDeDatos."<br>";
//redireccciono al controlador y el metodo logueoNotFound
// $this->redirect("Usuarios","logueoNotFound");
}
}
Users.php
public function loguearUsuario($idUsuario){
$query = "SELECT idUsuario FROM usuarios WHERE idUsuario = ".$idUsuario;
$resultado = $this->db()->query($query);
return $resultado;
}
In the browser, the result of the search in the bbdd I get false (result of the var_dump of UsersController.php), and as a consequence, the echo is empty, which, logically, does not make the comparison of the if.
View in the browser
bool (false) string (16) "[email protected]" USER NOT FOUND
APPLICANT USER: [email protected]
EXISTING USER BBDD: