how do I resolve the error Undefined property: stdClass ::

2

Notice: Undefined property: stdClass::$nome in C:\xampp\htdocs\peliculas\Model\Cliente.class.php on line 79

Notice: Undefined property: stdClass::$id in C:\xampp\htdocs\peliculas\Model\Cliente.class.php on line 80

How do I resolve this error? The line at issue for error 79 and 80 is:

$_SESSION['nomeCliente'] = $row->nome; $_SESSION['idCliente'] = $row->id;

public function logarCliente(){
      $c = new Conexao();

      $sql = mysqli_query($c->conectar(), "SELECT email, senha FROM clientes WHERE email = '{$this->getEmail()}' AND senha = '{$this->getSenha()}' AND ativo = 1");
      $c->desconectar();

      if(mysqli_num_rows($sql) > 0){
        $row = $sql->fetch_object();
        $_SESSION['nomeCliente'] = $row->nome;
        $_SESSION['idCliente'] = $row->id;
        $_SESSION['logado'] = true;

        return true;
      }else{
        return false;
      }
    }
    
asked by anonymous 14.11.2017 / 00:14

1 answer

3

It is impossible to extract id and nome from query . This is because in select only the columns email and senha were specified.

You need to change select or choose the fields correctly.

ACHO you intended to write to query like this:

$sql = mysqli_query($c->conectar(), "SELECT id, nome FROM clientes 
                                     WHERE email = '{$this->getEmail()}' 
                                     AND senha = '{$this->getSenha()}' 
                                     AND ativo = 1");
    
14.11.2017 / 00:21