I can not save variable data. (PHP and MySQLi)

0

It is a record in PHP, the problem is in the function that checks if a person is registered or not, always shows the data in Null.

if (isset($_REQUEST['entrar'])) {    
session_start();
$conexion = new Conexion();
$email = $_REQUEST['email'];
$pass = $_REQUEST['pass'];
$datosPersona = $conexion->comprobarPersona($email, $pass);      
if ($datosPersona != null) {
    $p = new Persona($datosPersona[0], $datosPersona[1], $datosPersona[2], $datosPersona[3]);
    $_SESSION["resultado"] = $p;
    header('Location: bienvenido.php');     
} else {
    $_SESSION["resultado"] = "Usuario o password incorrectos";
    header('Location: index.php');      
}

If we leave when checking Conexion () we find this:

function comprobarPersona($email, $pass) {
    $stmt = $this->conexion->prepare("SELECT * FROM personas WHERE email='" . $email . " AND pass='" . $pass . "'");
    $stmt->execute();
    $usuario = null;
    while ($row = $stmt->fetch()) {
        $usuario = array($row[0], $row[1], $row[2], $row[3]);
    }
    $stmt->close();
    return $usuario;

I've checked everything and I do not know what's wrong. It always stays in Null $ user. Thanks in advance.

    
asked by Estudiante Desarrollo Web 14.11.2018 в 19:13
source

1 answer

0

Try this way to validate that the query is running:

function comprobarPersona($email, $pass) {
    $stmt = $this->conexion->prepare("SELECT * FROM personas WHERE email='{$email}' AND pass='{$pass}' ");

    $usuario = null;
   !$stmt->execute()? die($this->conexion->error()) : "";
    while ($row = $stmt->fetch()) {
        $usuario = array($row[0], $row[1], $row[2], $row[3]);
    }

    $stmt->close();
return $usuario;
    
answered by 14.11.2018 / 19:39
source