Pass-through error by reference, insert into the bank

Asked

Viewed 90 times

-3

I’ve had the following mistakes:

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

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

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

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

And I have the following code below, someone can give me a light, it’s not possible to do it this way ?

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();
    }
}
  • 1

    At the very least insert is misspelled in query. It is written as inert

  • already fixed this and continues the same error, I am java programmer I am migrating to PHP, is that in java I could pass an object to the method that would use the Insert, but here PHP am not getting

  • presents some error

  • yes 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/bank/Banco.php on line 32 Notice: Only variables should be passed by Reference in /var/www/html/crud/bank/Banco.php on line 33

  • Behold bindParam and bindValue. The bindParam expects a reference, such as the notice indicates.

  • puts the rest of the code

  • just switched from bindParam to bindValue was that really thank you, guys worth the community is helping me a lot in this my entry in PHP, Thank you aeee

Show 3 more comments

1 answer

0

Change $post->getTitulo() by a variable.

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

You cannot change the value of what is being passed in bindParam, which is what $post->getTitulo() is making.

Browser other questions tagged

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