as a tool to resolve Undefined Property: stdClass error:

Asked

Viewed 9,327 times

3

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 solve this error the line in question error at 79 and 80 are:

$_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;
      }
    }

1 answer

4


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

You need to alter the select or choose the fields correctly.

THINK that you intended to write to query thus:

$sql = mysqli_query($c->conectar(), "SELECT id, nome FROM clientes 
                                     WHERE email = '{$this->getEmail()}' 
                                     AND senha = '{$this->getSenha()}' 
                                     AND ativo = 1");
  • I didn’t even see that obg by the Resp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.