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 }