Form query

This commit is contained in:
Andrea Moro 2025-01-23 11:30:30 +01:00
parent 559703caa2
commit 2c82d90dd4
3 changed files with 66 additions and 76 deletions

View file

@ -1,70 +0,0 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$host = "192.168.1.20";
$database = "ospedale";
$user = "pdo";
$password = "";
$datiPazienti = [];
try {
$connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
echo "Connected successfully<br>";
$prepare = $connection->prepare("SELECT cognome, nome, note FROM pazienti");
$prepare->execute();
if ($prepare->rowCount() > 0) {
$datiPazienti = $prepare->fetchAll();
}
$connection = null;
} catch (PDOException $e) {
die ("Error!: " . $e->getMessage() . "<br/>");
}
?>
<html lang="en">
<head>
<title>HTML</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
>
</head>
<body>
<main class="container">
<form>
<fieldset>
<label>
First name
<input
name="first_name"
placeholder="First name"
autocomplete="given-name"
/>
</label>
<label>
Email
<input
type="email"
name="email"
placeholder="Email"
autocomplete="email"
/>
</label>
</fieldset>
<input
type="submit"
value="Subscribe"
/>
</form>
</main>
</body>
</html>

View file

@ -4,7 +4,7 @@ error_reporting(E_ALL);
ini_set('display_errors', 1); ini_set('display_errors', 1);
$host = "192.168.1.20"; $host = "192.168.1.20";
$database = "ospedale"; $database = "tiro_piattello";
$user = "pdo"; $user = "pdo";
$password = ""; $password = "";
@ -14,7 +14,7 @@ try {
$connection = new PDO("mysql:host=$host;dbname=$database", $user, $password); $connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
echo "Connected successfully<br>"; echo "Connected successfully<br>";
$prepare = $connection->prepare("SELECT id, cognome, nome FROM medici"); $prepare = $connection->prepare("SELECT id, nome, sede FROM squadra");
$prepare->execute(); $prepare->execute();
if ($prepare->rowCount() > 0) { if ($prepare->rowCount() > 0) {
$datiMedici = $prepare->fetchAll(); $datiMedici = $prepare->fetchAll();
@ -38,12 +38,12 @@ try {
<body> <body>
<main class="container"> <main class="container">
<h1>Ricerca Pazienti per Medico</h1> <h1>Ricerca Squadra</h1>
<form action="result.php" method="POST"> <form action="result.php" method="POST">
<label for="medici">Seleziona Medico</label> <label for="squadra">Seleziona squadra</label>
<select id="medici" name="Medici"> <select id="squadra" name="squadra">
<?php foreach ($datiMedici as $med) { <?php foreach ($datiMedici as $med) {
echo "<option value='" . $med['id'] . "'>" . $med['cognome'] . " " . $med["nome"] . " </option>"; echo "<option value='" . $med['id'] . "'>" . $med['nome'] . " </option>";
} ?> } ?>
</select> </select>
<input <input

View file

@ -0,0 +1,60 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$host = "192.168.1.20";
$database = "tiro_piattello";
$user = "pdo";
$password = "";
$datiGiocatori = [];
$nomeSquadra = "";
try {
$connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
$squadraId = $_POST['squadra'];
$prepare = $connection->prepare("SELECT nome, cognome FROM atleta WHERE squadra = (?)");
$prepare->bindValue(1, $squadraId);
$prepare->execute();
if ($prepare->rowCount() > 0) {
$datiGiocatori = $prepare->fetchAll();
}
$prepare = $connection->prepare("SELECT nome FROM squadra WHERE id = (?)");
$prepare->bindValue(1, $squadraId);
$prepare->execute();
if($prepare->rowCount() > 0){
$nomeSquadra = $prepare->fetchAll();
$nomeSquadra = $nomeSquadra[0]["nome"];
}
$connection = null;
} catch (PDOException $e) {
die ("Error!: " . $e->getMessage() . "<br/>");
}
?>
<html lang="en">
<head>
<title>HTML</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
>
</head>
<body>
<main class="container">
<h1><?= $nomeSquadra ?></h1>
<?php foreach ($datiGiocatori as $med) {
echo "<h2>" . $med['nome'] . " </h2>";
echo "<h3>" . $med['cognome'] . " </h3>";
} ?>
</main>
</body>
</html>