PHP - Parse error: syntax error, unexpected 'public' (T_PUBLIC) in [closed]

-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 not find the reason for the error.

    
asked by anonymous 28.11.2016 / 12:04

2 answers

1

The else is missing, shortly after closing the foreach .

Here's how your code looks:

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

    }

Make this correction:

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

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

    
28.11.2016 / 12:11
1

You're missing a {} in your 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";
            }
    }
}
    
28.11.2016 / 12:07