PHP - Parse error: syntax error, Unexpected 'public' (T_PUBLIC) in

Asked

Viewed 3,568 times

-4

Good morning! I am with this code and I support the site, out of nowhere this error started to appear :(

public function getUrlcliente($cliente_id) {

        $parametro = "cliente_id=" . (int)$cliente_id;
        $url_cliente = $this->db->query("SELECT DISTINCT query as indice, keyword as url FROM url_cliente WHERE query = '" . $parametro . "'");

        if (empty($url_cliente)) {
            $url = "Erro - URL cliente não cadastrada";
        }
        else {
            foreach ($url_cliente as $row) {
                $url = $row->url;
            }

        if ($url_cliente->num_rows) {
                    return $url;
                }
        else
                {
                    return "Erro-Url inexistente";
                }
}

public function getcliente($cliente_id) {   // Dá erro nesta linha ** Parse error: syntax error, unexpected 'public' (T_PUBLIC) in ....

    $url_ex = $this->getUrlcliente($cliente_id);

    $query = $this->db->query("SELECT DISTINCT *, p.name AS name, p.image, '" . $this->getUrlcliente($cliente_id) . "' AS url_externa FROM cliente p";
    if ($query->num_rows) {
        return array(
            'cliente_id'       => $query->row['cliente_id'],
            'name'             => $query->row['name'],
            'image  '      => $query->row['image'],
            'url_externa'      => $query->row['url_externa'],
            'meta_description' => $query->row['meta_description'],
            'meta_keyword'     => $query->row['meta_keyword'],
            'tag'              => $query->row['tag']
        );
    } else {
        return false;
    }
}

}

I can’t find the reason for the mistake.

  • See if this helps you: http://stackoverflow.com/a/13341391/6101515

  • 2

    @Juniornunes, it’s okay that he didn’t post the whole code, but if the error occurs in the second function, we can believe that everything is within a class, besides, it’s clear that it’s missing is to close the keys at some point...

  • 1

    @Kennyrafael truth!

  • Simple typing error is out of scope, and you already have two answers explaining the error. It’s inattention when typing. Note that you were helped, it just doesn’t make sense to drop open the post because of this kind of error. There are two answers explaining the problem, and a comment just above. If you indent the code correctly it is evident that you have not closed one of the brackets.

  • I’m new to the forum, I didn’t understand how it worked. I’m sorry.

  • @Msergio does not need to apologize, everything is okay and you did nothing wrong, we are just explaining to you to understand the reason, and understand that it is nothing personal, only organization. We’re here to help. Don’t be discouraged to ask, the closure in this case was only a natural consequence, not a reproof. If you want to deal with it later, you have [help] with a number of issues that may help you locate, and also the Community FAQ on our 'meta" website, which is the site where the functioning of the main website is discussed.

  • @Bacco thank you so much. I am sending another question. rsrs Thank you.

Show 2 more comments

2 answers

2

Is missing close one {} in its first function!

public function getUrlcliente($cliente_id) {

    $parametro = "cliente_id=" . (int)$cliente_id;
    $url_cliente = $this->db->query("SELECT DISTINCT query as indice, keyword as url FROM url_cliente WHERE query = '" . $parametro . "'");

    if (empty($url_cliente)) {
        $url = "Erro - URL cliente não cadastrada";
    }
    else {
        foreach ($url_cliente as $row) {
            $url = $row->url;
        }

        if ($url_cliente->num_rows)
            {
                return $url;
            }
        else
            {
                return "Erro-Url inexistente";
            }
    }
}
  • In the first function, no foreach...

  • With this crooked indentation of the question, all we know is that one is missing }, the place is questionable :)

  • Yes, I deduced that from the logic of logic...ba dum tss But really, DEFICIL!

1


Is missing close the else, right after the closure of the foreach.

See how your code is:

    if (empty($url_cliente)) {
        $url = "Erro - URL cliente não cadastrada";
    }
    else {
        foreach ($url_cliente as $row) {
            $url = $row->url;

    }

Make that correction:

  else {
       foreach ($url_cliente as $row) {
            $url = $row->url;
       } // fecha o foreach
  } // fecha o else

Tip: Better identify your code. I discovered the syntax error thanks to a plugin I use in Sublime Text that shows syntax errors in a PHP script, but if it was complicated to find because of the lack of organization of the key provisions.

  • In fact the foreach is closed, it basically lacked to close the function really, unless it has some logic very different from what it seems to be...

  • 1

    @Kennyrafael is true, in fact what was missing close was the else. The compensation of his code confused me all :\

Browser other questions tagged

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