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
| <?php
if (isset($_GET) && !empty($_GET))
{ //verifie si l'email du formulaire existe déjà dans la table client
$n = $_GET['email'];
$sql = "SELECT idclient FROM client WHERE email=:email";
$reponse = $dbh->prepare($sql);
$reponse->execute(['email'=> $n]);
$donnees = $reponse->fetch();
//si l'email existe déjà
if ( $donnees )
{
$id = $donnees['idclient'];
}
//si l'email n'existe pas
else
{ //insère infos client dans table client
$sql = "INSERT INTO client(nom, prenom, email)
VALUES ( :nom, :prenom, :email)";
$stmt = $dbh->prepare ($sql);
$stmt->execute([
':nom' => $_GET['nom'],
':prenom' => $_GET['prenom'],
':email' => $_GET['email'],
]);
//récupère l'id du client inséré
$id=$dbh->lastInsertId();
}
//insère infos devis dans table devis
$sql2 = "INSERT INTO devis(surface, vitre, materiau, chauffage, numeroclient)
VALUES( :surface, :vitre, :materiau, :chauffage, :numeroclient)";
$stmt2 = $dbh->prepare( $sql2 );
$stmt2->execute([
':surface' => $_GET['surface'],
':vitre' => $_GET['vitre'],
':materiau' => $_GET['materiau'],
':chauffage' => $_GET['chauffage'],
':numeroclient' => $id,
]);
}
?> |
Partager