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
| $server = "localhost";
$user = "";
$pass = "";
$dbname = "Mon_site";
$prenom = $_POST["prenom"];
$email = $_POST["email"];
$nom = $_POST["nom"];
$tel = $_POST["tel"];
$entreprise = $_POST["entreprise"];
try{
//On se connecte à la BDD
$dbco = new PDO("mysql:host=$server;dbname=$dbname",$user,$pass);
$dbco->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//On insère les données reçues
$sth = $dbco->prepare("
INSERT INTO mon_site(id, prenom, nom, email, tel, reg_date, entreprise)
VALUES(:prenom, :nom, :email, :tel, :entreprise)");
$sth->bindParam(':prenom',$prenom);
$sth->bindParam(':nom',$nom);
$sth->bindParam(':email',$email);
$sth->bindParam(':tel',$tel);
$sth->bindParam(':entreprise',$entreprise);
$sth->execute();
}
catch(PDOException $e){
echo 'Impossible de traiter les données. Erreur : '.$e->getMessage();
}
?> |
Partager