1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <html>
<head><title>Formulaire de saisie </title></head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>
<h1>Inscrivez vous !!!</h1>
<h2>Entrez les données demandées :</h2>
<form name="inscription" method="post" action="form.php" </br>
<center>
Nom: <input type="text" name="prenom"/> </br>
</br>
Prenom : <input type="text" name="nom"/> </br>
</br>
<input type="submit" name="valider" value="Valider">
</form>
</center>
</body>
</html>
<?php
/* Connexion à une base */
$dsn = 'mysql:dbname=test;host=localhost';
$user = 'root';
$password = 'root';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connexion échouée : ' . $e->getMessage();
}
if (isset ($_POST['valider'])){
$prenom=$_POST['prenom'];
$nom=$_POST['nom'];
$dbh->exec("INSERT INTO infos_tbl(prenom,nom) VALUES($prenom','$nom')");
}
?> |
Partager