J'ai un petit souci avec une de mes requetes PDO, elle est correctement lue, il se connecte bien a ma BDD, je n'ai aucune erreur mais pourtant il y a aucune écriture dans ma BDD. J'ai assez bien vérifier qu'il n'y ait pas de virgule manquante ou quoi mais je sèche vraiment.
J'ai un formulaire (inscription.php) qui envoie les informations à une page de vérification. Cette page de vérification se connecte donc a la BDD via le fichier include/connection.php
Je vous mets le code de mes 3 fichiers
inscription.php
Code : Tout sélectionner
<?php include('include/connection.php') ?>;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="ma description" />
<meta name="keywords" content="péniche, écluses, paquebot, crise, décroissance" />
<link href="css/normalize.css" rel="stylesheet" type="text/css">
<link href="css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/nav.css" />
<link rel="stylesheet" type="text/css" href="css/formulaire.css" />
<title>KdM chauffage & plomberie (en construction)</title>
</head>
<body id="fullsite">
<header>
<div id="header">
<img src="http://placekitten.com/100/100" alt="KDM">
<h1 class="title">KDM <span>chauffage et plomberie</span></h1>
</div>
<div class="inscription">
<a alt="Inscrivez vous"href="inscription.php">Inscrivez vous</a>
<a alt="Inscrivez vous"href="connection.php">Connectez vous</a>
</div>
</header>
<?php include('include/nav.php');?>
<main>
<h2 class="titre">Pas encore inscrit ? Enregistrez vous !</h2>
<form class="contact-form" action="verification.php" method="post">
<div class="left">
<label for="nom">Nom</label>
<input type="text" name="nom" required="true" placeholder='ex: Michelin'/>
</div>
<div class="right">
<label for="prenom">Prénom</label>
<input type="text" name="prenom" required="true" placeholder='ex: Michel'/>
</div>
<div>
<label for="email">e-mail</label>
<input type="email" name="email" required="true" placeholder='ex : [email protected]'/>
</div>
<div class="right mdp">
<label for="mdp">Mot de passe</label>
<input type="password" name="mdp" required="true" placeholder='Votre mot de passe ici'/>
</div>
<div>
<label for="adresse">Adresse</label>
<input type="text" name="adresse" required="true" placeholder='ex: 25 Rue des ........'/>
</div>
<div class="right cp">
<label for="codepostal">Code postal</label>
<input type="text" name="codepostal" required="true" placeholder='ex: 1340'/>
</div>
<div>
<label for="region">Région</label>
<select name="region" id="region" required="true">
<option value="Région wallone">Région Wallone</option>
<option value="">Fédération Bruxelles Capital</option>
<option value="">Région Flamande</option>>
</select>
</div>
<div class="right fixe">
<label for="fixe">N° téléphone fixe</label>
<input type="tel" name="fixe" required="true" placeholder='ex: 02/394.45.32'/>
</div>
<div>
<label for="gsm">N° GSM</label>
<input type="tel" name="gsm" required="true" placeholder='ex: 0472/72.72.72'/>
</div>
<input type="submit" value="Envoyer" />
</form>
</main>
<footer>
</footer>
</body>
</html>
Code : Tout sélectionner
<?php include('include/connection.php');
if (!empty($_POST['nom']) && !empty($_POST['prenom']) && !empty($_POST['email']) && !empty($_POST['mdp'])){
echo 'Les champs obligatoires ont été complété !<br>';
$nom=htmlspecialchars($_POST['nom']);
$prenom=htmlspecialchars($_POST['prenom']);
$email=htmlspecialchars($_POST['email']);
$mdp=sha1($_POST['mdp']);
$adresse=htmlspecialchars($_POST['adresse']);
$codepostal=htmlspecialchars($_POST['codepostal']);
$region=htmlspecialchars($_POST['region']);
$fixe=htmlspecialchars($_POST['fixe']);
$gsm=htmlspecialchars($_POST['gsm']);
$token = uniqid(rand(), true);
setlocale (LC_TIME, 'fr_FR.utf8','fra');
$dateinsc = strftime("%A %d %B %Y");
echo $nom.'<br>'.
$prenom.'<br>'.
$email.'<br>'.
$mdp.'<br>'.
$adresse.'<br>'.
$codepostal.'<br>'.
$region.'<br>'.
$fixe.'<br>'.
$gsm.'<br>'.
$dateinsc.'<br>'.
$token.'<br>';
$reqmail = $bdd->prepare('SELECT email FROM membre WHERE email = ?');
$reqmail->execute(array($_POST['email']));
$donneesmail = $reqmail->fetch();
if (empty($donneesmail['email'])) {
echo 'OK';
$reponse = $bdd->prepare('INSERT INTO membre (nom, prenom, email, mdp, adresse, codepostal, region, fixe, gsm) VALUES (:nom, :prenom, :email, :mdp, :adresse, :codepostal, :region, :fixe, :gsm, :token)');
$reponse->execute(array(
'nom' => $nom,
'prenom' => $prenom,
'email' => $email,
'mdp' => $mdp,
'adresse' => $adresse,
'codepostal' => $codepostal,
'region' => $region,
'fixe' => $fixe,
'gsm' => $gsm,
'token' => $token));
echo '<body onLoad="alert(\'Les données ont été enregistrées, vous pouvez dès maintenant utiliser vos identifiants\')" >';
header ('refresh: 4,index.php');
} else {
echo 'Cette email existe déjà, veuillez recommencer.';
header ('refresh: 2,inscription.php');
}
} else {
echo 'Les champs "Nom", "Prenom", "Email" et "Mot de passe" doivent être complété';
}
?>
Code : Tout sélectionner
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=kdm', 'root', 'root', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
//mysql_query("SET NAMES UTF8");
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>