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 37 38
| <!doctype html>
<html>
<head>
<title>Exo PDO</title>
</head>
<body>
<form method="post" action="tst1.php">
<input type="text" name="pseudo" />
<input type="submit" value="OK" />
</form>
</body>
</html>
<?php
$user='root';
$pass='';
$dsn = 'mysql:host=localhost;dbname=test';
try{
$dbh = new PDO($dsn,$user,$pass);
}catch(PDOException $e){
echo("Erreur : " . $e->getMessage());
die("<br />N° :" . $e->getCode());
}
if(isset($_POST)){
if(!empty($_POST['nom'])){
$nom = $_POST['nom'];
$sql = "INSERT INTO membre (nom) VALUES ($nom)";
$result = $dbh->execute($sql);
print_r($dbh->errorInfo());
echo $result;
}else{
echo"tous les champs sont obligatoires";
}
}
?> |
Partager