Invalid variable

-2

I'm having a problem because of an invalid variable. It always tells me that the AlvaraAnexo variable 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;
}
    
asked by anonymous 31.03.2014 / 15:33

1 answer

3

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

First you should declare the function at the beginning or another file. Note that in function vc you have the variable $exibia['id'] I believe it should be replaced with only $id , because $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']);
}    
    
31.03.2014 / 15:45