0
<?php
include("conectar.php");
$id = $_REQUEST['id'];
if ($id == "")
{
$id = 1;
}
$sql = mysql_query("SELECT * FROM tb_trabalhador where codigo =".$id." limit 1");
include("paginacao.php"); // Chama o arquivo que monta a paginação. ex: << anterior 1 2 3 4 5 próximo >>
echo "<br><br>"; // Vai servir só para dar uma linha de espaço entre a paginação e o conteúdo
while ($exibe = mysql_fetch_array($sql)) {
echo "<table>";
echo "<tr><td>Nome:</td>";
echo "<td>".$exibe["Nome"]."</td></tr>";
echo "<tr><td>Morada:</td>"; echo "<td>";
if ($exibe['Morada']){ echo $exibe['Morada'];}else{echo 'N/D';} echo "</td></tr>";
echo "<tr><td>Tipo:</td>";echo"<td>";
if($exibe['Tipo']){ echo $exibe['Tipo'];}else{echo 'N/D';} echo "</td></tr>";
echo "<tr><td>Email:</td>"; echo "<td>";
if($exibe['Email']){ echo $exibe['Email'];}else{echo 'N/D';} echo "</td></tr>";
echo "<tr><td>Alvara Numero:</td>";echo"<td>";
if($exibe['AlvaraNumero']){ echo $exibe['AlvaraNumero'];}else{echo 'N/D';} echo " </td></tr>";
echo "</table>";
}
?>
The only problem with this code is Undefined index: id.
php pagination.
// Verifica se esta na primeira página, se nao estiver ele libera o link para anterior
if ( $pg > 0) {
echo "<a href=".$PHP_SELF."?pg=".($pg-1) ."class=pg><b>« anterior</b></a>";
} else {
echo "<font color=#CCCCCC>« anterior</font>";
}
// Faz aparecer os numeros das página entre o ANTERIOR e PROXIMO
for($i_pg=1;$i_pg<$quant_pg;$i_pg++) {
// Verifica se a página que o navegante esta e retira o link do número para identificar visualmente
if ($pg == ($i_pg-1)) {
echo " <span class=pgoff>[$i_pg]</span> ";
} else {
$i_pg2 = $i_pg-1;
echo " <a href=".$PHP_SELF."?pg=$i_pg2 class=pg><b>$i_pg</b></a> ";
}
}
// Verifica se esta na ultima página, se nao estiver ele libera o link para próxima
if (($pg+2) < $quant_pg) {
echo "<a href=".$PHP_SELF."?pg=".($pg+1)." class=pg><b>próximo »</b></a>";
} else {
echo "<font color=#CCCCCC>próximo »</font>";
}
?>
In this last code I’m having trouble relating the first to the second. And so I left an old code.
EDIT: In the first code will be to show the data and in the second will make the pagination
You have an SQL injection vulnerability in the first query of your first file and several potential XSS injection vulnerabilities.
– luiscubal
Would not be
$sql = mysql_query("SELECT * FROM tb_trabalhador where codigo =".$id." limit 1");
? but be careful with this type of solution it is totally vulnerable– Paulo Roberto Rosa
@Pauloroberto In PHP,
"foo$bar"
is equivalent to"foo" . $bar
. (as opposed to strings with plicas,'foo$bar'
, where this substitution does not occur) http://php.net/manual/en/language.operators.string.php– luiscubal
Correct. But this is only for personal use on my computer. For me to control certain data.
– ChrisAdler
@luiscubal strange.. and when you want to put a string that has the word $id inside it without wanting the value of the variable?
– Paulo Roberto Rosa
@Pauloroberto Use plicas.
'foo$id'
is not converted.– luiscubal