Parse error: syntax error, Unexpected 'public' (T_PUBLIC)

Asked

Viewed 329 times

-2

Hello beast friends in PHP, can anyone help me? I can’t find the error in the following public function:

public function addLike($user_id, $tweet_id, $get_id){
        $stmt = $this->pdo->prepare("UPDATE 'tweets' SET 'likesCount' = 'likesCount' +1 WHERE 'tweetID' = :tweet_id");
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->execute();

        $this-> create('likes', array('likeBy' => $user_id, 'likeOn' => $tweet_id));
    }

If anyone knows the mistake and can help, I thank them. I embrace them all.

1 answer

1

The public should only be used in functions within classes (as well as the private and the protected), ex.:

class Classe {
  public function addLike(){
     // código
  }
}

In your case, the function cannot be declared as public. More on the subject you can refer to official documentation.

Browser other questions tagged

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