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 39 40 41 42 43 44 45 46 47 48 49 50
| <?php
if (!empty($_POST["valider"]))
{
if(!empty($_POST["nom"]) && !empty($_POST["prenom"]) && !empty($_POST["age"]) && !empty($_POST["adresse"]) && !empty($_POST["ville"]) && !empty($_POST["mail"]))
{
//////////// CONNEXION A LA BASE DE DONNEES /////////////////
define ('USER1', 'root');
define ('PASS', '0000');
define ('DSN', 'mysql:host=localhost;dbmane=magasin');
try
{
$connexion_bdd = new PDO(DSN, USER1, PASS);
}
catch (PDOException $e)
{
trigger_error($e->getMessage(),E_USER_ERROR);
}
$requete = 'INSERT INTO client (id_client, nom, prenom, age, adresse, ville, mail) VALUES (:id_client , :nom , :prenom , :age , :adresse , :ville , :mail)';
$resultat = $connexion_bdd->prepare($requete);
$id_client = '\N';
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$age = $_POST['age'];
$adresse = $_POST['adresse'];
$ville = $_POST['ville'];
$mail = $_POST['mail'];
$resultat->execute(array(':id_client'=>$id_client, ':nom'=>$nom, ':prenom'=>$prenom,':age'=>$age, ':adresse'=>$adresse, ':ville'=>$ville, ':mail'=>$mail));
if($connexion_bdd->lastInsertId() != "0")
{
print("<div class=\"centrer\">Enregistrement effectué avec succès !</div>");
}
else
{
print("<div class=\"centrer\">Enregistrement non effectué</div>");
}
$connexion_bdd = NULL;
/////////// FIN OPERATION BASE DE DONNEES ////////////
}
else
{
print("Pour continuer tous les champs doivent être complétés !");
}
}
?> |
Partager