Invalid variable

Asked

Viewed 145 times

-2

I have a problem because of an invalid variable. It always tells me that the variable AlvaraAnexo is invalid.

<?php
include("conectar.php");
$id = $_GET['id'];
$sql = mysql_query("Select* From tb_trabalhador WHERE id = $id");



function apresentarAlvara ($id, $AlvaraAnexo) {
$href = 'MostrarAlvara.php?id='.$id.'&amp;documento='.$AlvaraAnexo;
$title = 'Clique para abrir documento';

$html = '
<p>
Visualizar documento Alvara: <a href="MostrarAlvara.php?id='.$exibe['id'].'">Ver PDF  </a>
</p>';

return $html;
}
  • You can put the error message?

  • Your while is open, missing }. How do you call the function? and as @lost requested, add the error you gave.

  • pq essa Function está dentro de um while?

  • Edit the question to put more details, preferably the full code, otherwise you can’t even begin to help. Try to edit at once than make several edits, because after 10 edits the question can become community wiki.

  • @nano.Next, be careful when making these very small edits (especially when the question has already been edited), because after 5 different people edit it, it also becomes a community wiki. (editing is welcome, but when the question is very new, it pays to wait a little, usually the author edits it back and a half)

1 answer

3


If the function definition is within the while error will be issued:
Fatal error: Cannot redeclare: apresentarAlvara.

First you should declare the function at the beginning or in another file. See that in the function vc has the variable $exibia['id'] I believe that it should be replaced by only $id, for $exibi is not a global variable.

<?php
function apresentarAlvara ($id, $AlvaraAnexo) {
$href = 'MostrarAlvara.php?id='.$id.'&amp;documento='.$AlvaraAnexo;
$title = 'Clique para abrir documento';

$html = '
<p>
Visualizar documento Alvara: <a href="MostrarAlvara.php?id='.$id.'">Ver PDF  </a>
</p>';

return $html;
}


include("conectar.php");
$id = $_GET['id'];
$sql = mysql_query("Select* From tb_trabalhador WHERE id = $id");
while($exibe = mysql_fetch_array($sql)){
    apresentarAlvara($exibi['id'], $exibi['nome']);
}    

Browser other questions tagged

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