Error in PHP code

Asked

Viewed 61 times

-2

My code is part of a virtual store project, and is giving the following error: inserir a descrição da imagem aqui

Follow the code below:

<?php class Login extends BD{

    private $prefixo = 'ibicor_';
    private $tabela = 'loja_clientes';
    private $email;
    private $senha;

    public function setEmail($mail){
        $this->email = $mail;
    }

    private function getEmail(){
        return $this->email;
    }

    public function setSenha($pass){
        $this->senha = $pass;
    }

    private function getSenha(){
        return $this->senha;
    }

    private function validar(){
        $strSQL = "SELECT * FROM '".$this->tabela."' WHERE email_log = ? AND senha_log = ?";
        $stmt = self::conn()->prepare($strSQL);
        $stmt->execute(array($this->getEmail(), $this->getSenha()));
        return ($stmt->rowCount() > 0) ? true : false;
    }

    public function logar(){
        if($this->validar()){
            $atualizar = self::conn()->prepare("UPDATE '".$this->tabela."' SET data_log = NOW() WHRE email_log = ? AND senha_log = ?");
            $atualizar->execute(array($this->getEmail(), $this->getSenha()));

            $_SESSION[$this->prefixo.'emailLog'] = $this->getEmail();
            $_SESSION[$this->prefixo.'senhaLog'] = $this->getSenha();
            return true;
        }else{
            return false;   
        }
    }

    public function isLogado(){
        if(isset($_SESSION[$this->prefixo.'emailLog'], $_SESSION[$this->prefixo.'senhaLog'])){
            return true;
        }else{
            return false;
        }
    }

    public function deslogar(){
        if($this->isLogado()){
            unset($_SESSION[$this->prefixo.'emailLog']);
            unset($_SESSION[$this->prefixo.'senhaLog']);
            return true;
        }else{
            return false;
        }
    }
}
?>
  • 1

    And be careful with the prints that have personal information. Your email is visible in the error image, just your password also appeared there.

  • It’s all test email

  • Place the error as text, not image, because it makes it difficult to view.

2 answers

3

Syntax error table names or fields should not be in single quotes. This holds for both select and update code.

"SELECT * FROM '".$this->tabela."'
               ^                 ^
               |  causa do erro  |
  • I’ve removed the single quotes, but the error remains

1

At the time you pass the table name you pass only its name, without involving it with single quotes..

"SELECT * FROM ".$this->tabela." WHERE email_log = ? AND senha_log = ?";

And here too.

"UPDATE ".$this->tabela." SET data_log = NOW() WHRE email_log = ? AND senha_log = ?"
  • I’ve removed the single quotes, but the error remains

Browser other questions tagged

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