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
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body> <?php
// put your code here
try {
$connexion=new PDO("mysql:host=localhost;dbname=pdo",'root','');
} catch (Exception $exc) {
die($exc->getMessage());
}
if(isset($_POST['ajouter']))
{
$requete=$connexion->prepare("insert into personne values(id=:id,nom=:nom,prenom=:prenom,age=:age)");
$requete->execute(array(
"id"=>'',
"nom"=>$_POST['nom'],
"prenom"=>$_POST['prenom'],
"age"=>$_POST['age']
));
}
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<p> <label> nom:</label> <input type="text" name="nom"/></p>
<p> <label> prenom:</label><input type="text" name="prenom"/></p>
<p> <label> age:</label><input type="text" name="age"/></p>
<p> <input type="submit" name="ajouter" value="ajouter"/></p>
</form>
<a href="connexion_PDO.php">Revenir a la page principale </a>
</body>
</html> |
Partager