-3

Tive os seguintes erros:

Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 30

Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 31

Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 32

Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 33

E tenho o seguinte código abaixo, alguém pode me dar uma luz, não é possível fazer desse jeito ?

public function insert($table, Post $post){       
    if(empty($table) == false){
        $this->stm = $this->pdo->prepare("insert into ".$table." (titulo, data_criado, corpo, autor) values(?, ?, ?, ?)");
        $this->stm->bindParam(1, $post->getTitulo());
        $this->stm->bindParam(2, $post->getData_criacao());
        $this->stm->bindParam(3, $post->getCorpo());
        $this->stm->bindParam(4, $post->getAutor());

        $this->stm->execute();
    }
}
8
  • 1
    No minimo insert está mal escrito na query. Está escrito como inert
    – Isac
    24/03/2018 às 1:26
  • já corrigi isso e continua o mesmo erro, sou programador java estou migrando para PHP, é que no java dava para passar um objeto para o método que iria usar o insert, mas aqui PHP não estou conseguindo 24/03/2018 às 1:28
  • apresenta algum erro 24/03/2018 às 1:35
  • sim esses ai Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 30 Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 31 Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 32 Notice: Only variables should be passed by reference in /var/www/html/crud/banco/Banco.php on line 33 24/03/2018 às 1:36
  • Veja bindParam e bindValue. O bindParam espera uma referência, tal como o próprio notice indica.
    – Isac
    24/03/2018 às 1:38

1 Resposta 1

0

Troque $post->getTitulo() por uma variável.

Exemplo: $titulo = $post->getTitulo();

Você não pode alterar o valor do que está sendo passado no bindParam, que é o que $post->getTitulo() está fazendo.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .