Skip to content

Instantly share code, notes, and snippets.

@salvatorecapolupo
Last active May 23, 2022 13:37
Show Gist options
  • Save salvatorecapolupo/82bed4dc4b96e4c841bb02382920f121 to your computer and use it in GitHub Desktop.
Save salvatorecapolupo/82bed4dc4b96e4c841bb02382920f121 to your computer and use it in GitHub Desktop.
PHP utile, molto utile :-)
<html>
<head>
<title>FORM</title>
</head>
<body>
<h1>Inserimento cliente</h1>
<form method="post" action="insert-db.php"> <!-- importante! -->
<table border=1>
<tr>
<td><label>Nome: </label></td>
<td><input type="text" name="nome" id="nome"/></td> <!-- importante! -->
</tr>
<tr>
<td><label>Cognome: </label></td>
<td><input type="text" name="cognome" id="cognome"/></td> <!-- importante! -->
</tr>
<tr>
<td><label>Codice Fiscale: </label></td>
<td><input type="text" name="codfisc" id="codfisc"/></td> <!-- importante! -->
</tr>
<tr>
<td align='center'><input type="submit" name="invia" value="Invia"></td> <!-- importante! -->
<td align='center'><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<title>Insert DB</title>
</head>
<body>
<?php
// creazione connessione
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "concessionarie2";
// verifica connessione
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// acquisizione dati dal form
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$codfisc = $_POST['codfisc'];
// costruzione query
$sql = "INSERT INTO clienti (codiceFiscale, nome, cognome)VALUES ('$codfisc','$nome','$cognome')";
//conferma o messaggio di errore
if ( $conn->query($sql) === TRUE ) {
echo 'OK, dato inserito!';
} else {
echo 'Errore, dato non inserito: ' . $sql . '<br>' . $conn->error;
}
//chiusura connessione
$conn->close();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment