Aggiunta pagina con statement
This commit is contained in:
79
home_stmt.php
Normal file
79
home_stmt.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
require_once "_db_config.php";
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<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
|
||||
// BREAK THE SPEAKERS
|
||||
// verifichiamo se l'utente abbia inviato i dati dal form
|
||||
if(isset($_POST['cerca']) && !empty($_POST['cognome'])){
|
||||
$cognome_ricercato = $_POST['cognome'];
|
||||
|
||||
// 1. Prepariamo la nostra query con segnaposto
|
||||
$sql = "SELECT idTessera, cognome, nome, email FROM motociclista WHERE cognome = ?";
|
||||
|
||||
// 2. Prepariamo il nostro statement
|
||||
if($stmt = mysqli_prepare($conn, $sql)){
|
||||
mysqli_stmt_bind_param($stmt, "s", $cognome_ricercato);
|
||||
|
||||
// 3. Eseguiamo il nostro statement
|
||||
mysqli_stmt_execute($stmt);
|
||||
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
|
||||
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 "Il cognome inserito non risulta tra l'elenco dei motociclisti";
|
||||
}
|
||||
|
||||
// 4. Ricordiamoci di chiudere lo statement
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo "Inserisci i dati correttamente";
|
||||
}
|
||||
// Ricordarsi di chiudere la connessione
|
||||
mysqli_close($conn);
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user