Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

variabile nella istruzio select

11 views
Skip to first unread message

Akery

unread,
Jul 1, 2022, 8:04:47 AM7/1/22
to
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

bramante

unread,
Jul 1, 2022, 8:56:14 AM7/1/22
to
Il 01/07/22 14:04, Akery ha scritto:
verifica tramite un

echo $_POST['CodFis'];

il valore del campo

PS
$_POST (in maiuscolo php è case sensitive)


Akery

unread,
Jul 4, 2022, 8:19:19 AM7/4/22
to
grazie

Corrado Modica

unread,
Sep 8, 2022, 5:50:33 AM9/8/22
to
Il 01/07/2022 14:04, Akery ha scritto:
> tutto funziona correttamente se la riga
>
> $sql = "SELECT * FROM check_temp where cf='".$cfisc."'";


$sql = "SELECT * FROM check_temp where cf='$cfisc'";


--
Questa email è stata esaminata alla ricerca di virus dal software antivirus Avast.
www.avast.com
0 new messages