76 lines
2.5 KiB
PHP
76 lines
2.5 KiB
PHP
<?php
|
|
require_once "_db_config.php";
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Ricerca Motociclisti</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
|
|
<h2>Cerca nel Registro Motociclisti</h2>
|
|
|
|
<!-- FORM DI RICERCA -->
|
|
<div class="search-box">
|
|
<form action="" method="POST">
|
|
<label for="cognome">Inserisci il cognome:</label>
|
|
<input type="text" name="cognome" id="cognome" placeholder="Es: Rossi" required>
|
|
<button type="submit" name="cerca">Cerca ora</button>
|
|
|
|
</form>
|
|
</div>
|
|
|
|
<?php
|
|
// Eseguiamo la ricerca solo se il form è stato inviato
|
|
if (isset($_POST['cerca']) && !empty($_POST['cognome'])) {
|
|
|
|
$cognome_ricercato = $_POST['cognome'];
|
|
|
|
// 1. Query con segnaposto può essere attaccata da sql injection 'OR '1'='1
|
|
// 2. SELECT ... WHERE cognome = ''; DROP TABLE motociclista; --';
|
|
|
|
$sql = "SELECT idTessera, cognome, nome, email FROM motociclista WHERE cognome = '$cognome_ricercato'";
|
|
|
|
if ($result = mysqli_query($conn, $sql)) {
|
|
|
|
if (mysqli_num_rows($result) > 0) {
|
|
echo "<h3>Risultati per: " . htmlspecialchars($cognome_ricercato) . "</h3>";
|
|
echo "<table>
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Cognome</th>
|
|
<th>Nome</th>
|
|
<th>Email</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>";
|
|
//fetch vuol dire vai a prendere
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
echo "<tr>";
|
|
echo "<td>" . htmlspecialchars($row['idTessera']) . "</td>";
|
|
echo "<td>" . htmlspecialchars($row['cognome']) . "</td>";
|
|
echo "<td>" . htmlspecialchars($row['nome']) . "</td>";
|
|
echo "<td>" . htmlspecialchars($row['email']) . "</td>";
|
|
echo "</tr>";
|
|
}
|
|
|
|
echo "</tbody></table>";
|
|
} else {
|
|
echo "<p class='no-results'>Nessun motociclista trovato con cognome: <strong>" . htmlspecialchars($cognome_ricercato) . "</strong></p>";
|
|
}
|
|
|
|
|
|
}
|
|
} else {
|
|
echo "<p>Inserisci un cognome e premi 'Cerca' per visualizzare i dati.</p>";
|
|
}
|
|
|
|
mysqli_close($conn);
|
|
?>
|
|
|
|
</body>
|
|
</html>
|