salve a tutti,
sono un neofita del linguaggio php e ho incontrato la mia prima
difficoltà, credo banale per la maggior parte del gruppo, ve la espongo:
ho la pagina index.html
<html lang="en">
<head>
<title>My State</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
</head>
<body>
<form action="mystateinvia.php" method="post">
inserisci il tuo codice fiscale: <input type="text" name =
"CodFis"> </br>
<input type="submit" />
</form>
</body>
</html>
e la pagina php
<?php
$servername = "mioserver";
$username = "username";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$cfisc=$_post["CodFis"];
$sql = "SELECT * FROM check_temp where cf='".$cfisc."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$tabella="";
// output data of each row
while($row = $result->fetch_assoc()) {
$tabella.=
"<tr><td>".$row["nome"]."</td><td>".$row["cognome"]."</td><td>".$row["categoria"]."</td><td>".$row["afferenza"]."</td><td>".$row["inizio_rapporto"]."</td><td>".$row["fine_rapporto"]."</td><td>".$row["stato"]."</td></tr>";
}
} else {
echo $cfisc;
echo "0 results";
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Personale DICMaPI</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="
https://cdn.jsdelivr.net/npm/boot...@4.6.1/dist/css/bootstrap.min.css">
<script
src="
https://cdn.jsdelivr.net/npm/jqu...@3.6.0/dist/jquery.slim.min.js"></script>
<script
src="
https://cdn.jsdelivr.net/npm/popp...@1.16.1/dist/umd/popper.min.js"></script>
<script
src="
https://cdn.jsdelivr.net/npm/boot...@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
</head>
<div class="container">
<h2></h2>
<p>Personale DICMaPI</p>
<table class="table">
<thead>
<tr>
<th>Nome</th>
<th>Cognome</th>
<th>categoria</th>
<th>afferenza</th>
<th>inizio rapporto</th>
<th>fine rapporto</th>
<th>stato</th>
</thead>
<tbody><!-- comment -->
<?php echo $tabella; ?>
</tbody>
</table>
</div>
</html>
tutto funziona correttamente se la riga
$sql = "SELECT * FROM check_temp where cf='".$cfisc."'";
è scritta senza il where
$sql = "SELECT * FROM check_temp";
cosa sto sbagliando nell'istruzione?
Grazie
--
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
https://www.avast.com/antivirus