0

I have an error with the login that I cannot resolve.

blok.php

class General extends Dbh {

   public function login(){
    if(isset($_POST['add'])){
    if(!empty($_POST['email']) && !empty($_POST['pass'])){
        $sql = "SELECT * FROM usuario WHERE email = :email AND pass = :pass";
        $stmt = $this->connect()->prepare($sql);
        $stmt->execute(array(':email' => $_POST['email'], ':pass' => $_POST['pass']));
        $fila = $stmt->fetchAll();

        if($fila > 0){
            $_SESSION['log'] = "SI";
            $_SESSION['user']  = $fila['name'];
            header('location: ../');
        } else {
            echo 'Email and Password incorrect';
        }
     } else {
        echo 'Enter email user and password';
    }
 }
}

public function getUser($user){
 $sql = "SELECT * FROM user WHERE name = ?";
 $stmt = $this->connect()->prepare($sql);
 $stmt->execute(array($user));

 $resultado = $stmt->fetchAll();
 return $resultado;
 }
}

index.php

session_start();
 if($_SESSION['logueado'] != "SI"){
 header('location: login');
 exit();
}

include_once('blok.php');

$blok = new General();

$name = $_SESSION['log'];

$user = $blok->getUser($name);

Errors

Notice: Undefined index: name in...

Notice: Array to string conversion in..

Error echo 'Hi'.$user; => Hi Array

Using var_dump on the variable $user array is 0

var_dump($user); => array(0) { }

Error var_dump($_SESSION); => array(2) { ["log"]=> string(2) "SI" ["user"]=> NULL }

Sebastian
  • 135
  • 1
  • 6
  • fetch_result ? then fetchAll – Jerson Nov 10 '20 at 02:09
  • I don't understand – Sebastian Nov 10 '20 at 02:11
  • Please format your question properly and provide clear examples of errors. Currently, you have just dumped a bunch of errors/warnings without any lines numbers. – waterloomatt Nov 10 '20 at 03:48
  • `fetchAll` likely returns an array of data and you are treating it as a string, `'Hi'.$user;`. You need to either, a.) return a string, or b.) return an array and then access the string you want. Finally, turn on error reporting https://stackoverflow.com/a/21429652/296555. – waterloomatt Nov 10 '20 at 03:50

0 Answers0