Voila les codes :
inscription_parent.html :
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>Inscription parent</title>
</head>
<body>
<form method="POST" action="inscription_parent.php">
<p>
<label for="nom">Nom :</label>
<input type="text" name="nom" id="nom" />
<br></br>
<label for="prenom">Prenom :</label>
<input type="text" name="prenom" id="prenom" />
<br></br>
<label for="adresse">Adresse :</label>
<input type="text" name="adresse" id="adresse" />
<br></br>
<label for="ville">Ville :</label>
<input type="text" name="ville" id="ville" />
<br></br>
<label for="mail">Mail :</label>
<input type="text" name="mail" id="mail" />
<br></br>
<label for="pseudo">Pseudo :</label>
<input type="text" name="pseudo" id="pseudo" />
<br></br>
<label for="mdp">Mot de passe :</label>
<input type="text" name="mdp" id="mdp" />
<br></br>
<label for="mdp2">Confirmation mot de passe :</label>
<input type="text" name="mdp2" id="mdp2" />
<br></br>
<form name="submit" method="POST" action="connexion.html">
<input type="submit" name="submit" value="Envoyer"/>
</form>
inscription_parent.php :
error_reporting(E_ALL);
if(isset($_POST['submit']))
{
header('Location: index.html');
$bdd = new PDO('mysql:host=localhost;dbname=projet;charset=utf8', 'root', '');
try
{
$bdd = new PDO('mysql:host=localhost;dbname=projet;charset=utf8', 'root', '');
$req = "INSERT INTO inscription_parent (nom, prenom, adresse, ville, mail, pseudo, mdp, mdp2)";
$req .= " VALUES ";
$req .= "(:nom, :prenom, :adresse, :ville, :mail, :pseudo, :mdp, :mdp2)";
$stmt = $bdd->prepare($req);
$stmt->bindValue('nom',htmlentities(trim($_POST['nom'])),PDO::PARAM_STR);
$stmt->bindValue('prenom',htmlentities(trim($_POST['prenom'])),PDO::PARAM_STR);
$stmt->bindValue('adresse',htmlentities(trim($_POST['adresse'])),PDO::PARAM_STR);
$stmt->bindValue('ville',htmlentities(trim($_POST['ville'])),PDO::PARAM_STR);
$stmt->bindValue('mail',htmlentities(trim($_POST['mail'])),PDO::PARAM_STR);
$stmt->bindValue('pseudo',htmlentities(trim($_POST['pseudo'])),PDO::PARAM_STR);
$stmt->bindValue('mdp',htmlentities(trim($_POST['mdp'])),PDO::PARAM_STR);
$stmt->bindValue('mdp2',htmlentities(trim($_POST['mdp2'])),PDO::PARAM_STR);
if (!$stmt->execute()) {
throw new PDOException('insertion impossible');
}
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
}
connexion.html :
<head>
<meta charset="utf-8" />
</head>
<body>
<form method="POST" action="connexion.php">
<p>
<label for="username">Pseudo :</label>
<input type="text" name="username" id="username" />
<br></br>
<label for="password">Mot de passe :</label>
<input type="text" name="password" id="password" />
<br></br>
<label for="password2"> Retapez votre mot de passe :</label>
<input type="text" name="password2" id="password2" />
<br></br>
<input type="submit" name="submit" value="Envoyer">
</p>
</form>
</body>
connexion.php :
error_reporting(E_ALL);
//----------------------------------------//
//connexion à la BDD
//----------------------------------------//
require_once "cnxBDD.php";
//----------------------------------------//
//Récupération "propre" des variables
//----------------------------------------//
$username = !empty($_POST['username']) ? htmlentities(trim($_POST['username'])) : NULL;
$password = !empty($_POST['password']) ? htmlentities(trim($_POST['password'])) : NULL;
$password2 = !empty($_POST['password2']) ? htmlentities(trim($_POST['password2'])) : NULL;
//----------------------------------------//
// Traitement du SUBMIT
//----------------------------------------//
if($username&&$password&&$password2) {
if($password === $password2){
//On vérifie si l'utilisateur n'existe pas déjà :
try{
$sql = "SELECT * FROM connexion WHERE username=:username";
$a_data = array(":username"=>$username);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
//on place le résultat de la requête dans un ARRAY
$result = $stmt->fetchAll();
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo "</pre>";
exit();
}
if(count($result)>0){
//l'utilisateur existe déjà...
echo"Ce pseudo n'est pas disponible";
}else{
try{
$sql = "INSERT INTO connexion (username, password) VALUES (:username, :password)";
$a_data = array(":username" => $username, ":password" => $password);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
$id = $bdd->lastInsertId(); //récupère l'ID créé lors de l' INSERT dans la BDD
if($id){
echo "<br> Enregistrement effectué !. ID = ".$id;
//Si tu veux une redirection automatique : header("Location: connexion.php");
// sinon avec un Lien :
echo "<a href='index2.html'> Connectez-vous </a>";
}else{
echo "<br> Erreur lors de l'enregistrement !";
print_r($a_data);
}
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo "</pre>";
exit();
}
}
}else{
echo "Les deux passwords doivent être identiques";
}
}
inscription_enfant.html :
error_reporting(E_ALL);
require_once "cnxBDD.php";
try{
$sql = "SELECT * FROM ecole ";
$stmt = $bdd->prepare($sql);
$res = $stmt->execute();
if($res){
$arr_ecoles = $stmt->fetchAll();
//le temps des tests :
echo "<pre>";
//print_r($arr_ecoles);
echo "</pre>";
}else{
echo "<br> Erreur dans l’exécution de la requête :".$sql;
exit();
}
}catch (Exception $e){
die('Erreur : ' . $e->getMessage());
}
?>
<html>
<head>
<meta charset="utf-8" />
<title>Inscription enfant</title>
</head>
<form method="POST" action="traitement_enfant.php">
<label for="nom">Nom :</label>
<input type="text" name="nom" id="nom" />
<br></br>
<label for="prenom">Prenom :</label>
<input type="text" name="prenom" id="prenom" />
<br></br>
<label for="nom_ecole">Ecole :</label>
<select id='ecole' name='ecole' onChange='nom_ecole();'>
<?php
if($arr_ecoles){
foreach($arr_ecoles as $ECOLE){
echo "<option value='".$ECOLE['id']."'>".$ECOLE['nom']."</option>";
}
}
?>
</select>
<br></br>
<input type="submit" name="submit" value=" Envoyer ">
</form>
</form>
</body>
traitement_enfant.php :
error_reporting(E_ALL);
require_once "cnxBDD.php";
$nom = isset($_POST['nom']) ? htmlentities(trim($_POST['nom'])) : '';
$prenom = isset($_POST['prenom']) ? htmlentities(trim($_POST['prenom'])) : '';
$id_ecole = isset($_POST['ecole']) ? htmlentities(trim($_POST['ecole'])) : '';
if(isset($_POST['submit'])) {
try {
$a_datas = array(":nom"=>$nom,":prenom"=>$prenom,":id_ecole"=>$id_ecole);
$req = "INSERT INTO inscription_enfant (nom, prenom, id_ecole)
VALUES(:nom, :prenom, :id_ecole)";
$stmt = $bdd->prepare($req);
$stmt->execute($a_datas);
echo " Enregistrement de votre enfant !";
echo "<a href='index2.html'>connextez vous</a>";
}catch (Exception $e){
echo "<br>Erreur : " . $e->getMessage();
echo "<br> <b>Requete :<b><br> ".$req;
echo "<br> params :<br><pre>";
print_r($a_datas);
echo "</pre>";
exit();
}
}
garderie.html :
<head>
<meta charset="utf-8" />
<h1> Reservation garderie </h1>
</head>
<body>
<form method="POST" action="reservation_garderie.php">
<form>
<table>
<tr>
<th> </th>
<th> Lundi </th>
<th> Mardi </th>
<th> Mercredi </th>
<th> Jeudi </th>
<th> Vendredi </th>
</tr>
<tr>
<th> Matin </th>
<th> <INPUT type="checkbox" name="lundi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="mardi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="mercredi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="jeudi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="vendredi_matin" value="1"> </th>
</tr>
<tr>
<th> Soir </th>
<th> <INPUT type="checkbox" name="lundi_soir" value="1"> </th>
<th> <INPUT type="checkbox" name="mardi_soir" value="1"> </th>
<th> <INPUT type="checkbox" name="mercredi_soir" value="1"> </th>
<th> <INPUT type="checkbox" name="jeudi_soir" value="1"> </th>
<th> <INPUT type="checkbox" name="vendredi_soir" value="1"> </th>
</tr>
</table>
</body>
<br></br>
<INPUT TYPE="submit" NAME="submit" VALUE=" Envoyer ">
</form>
garderie.php :
error_reporting(E_ALL);
require_once "cnxBDD.php";
$nom = isset($_POST['nom']) ? htmlentities(trim($_POST['nom'])) : '';
$prenom = isset($_POST['prenom']) ? htmlentities(trim($_POST['prenom'])) : '';
$id_ecole = isset($_POST['ecole']) ? htmlentities(trim($_POST['ecole'])) : '';
if(isset($_POST['submit'])) {
try {
$a_datas = array(":nom"=>$nom,":prenom"=>$prenom,":id_ecole"=>$id_ecole);
$req = "INSERT INTO inscription_enfant (nom, prenom, id_ecole)
VALUES(:nom, :prenom, :id_ecole)";
$stmt = $bdd->prepare($req);
$stmt->execute($a_datas);
}catch (Exception $e){
echo "<br>Erreur : " . $e->getMessage();
echo "<br> <b>Requete :<b><br> ".$req;
echo "<br> params :<br><pre>";
print_r($a_datas);
echo "</pre>";
exit();
}
}
$lundi_matin = isset($_POST['lundi_matin']) ? 1 : 0;
$mardi_matin = isset($_POST['mardi_matin']) ? 1 : 0;
$mercredi_matin = isset($_POST['mercredi_matin']) ? 1 : 0;
$jeudi_matin = isset($_POST['jeudi_matin']) ? 1 : 0;
$vendredi_matin = isset($_POST['vendredi_matin'])? 1 : 0;
$lundi_soir = isset($_POST['lundi_soir']) ? 1 : 0;
$mardi_soir = isset($_POST['mardi_soir']) ? 1 : 0;
$mercredi_soir = isset($_POST['mercredi_soir']) ? 1 : 0;
$jeudi_soir = isset($_POST['jeudi_soir']) ? 1 : 0;
$vendredi_soir = isset($_POST['vendredi_soir']) ? 1 : 0;
try{
$sql = "INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = (:lundi_matin, :lundi_soir, :mardi_matin, :mardi_soir, :mercredi_matin, :mercredi_soir, :jeudi_matin, :jeudi_soir, :vendredi_matin, :vendredi_soir)";
$a_data = array(":lundi_matin"=> $lundi_matin
,":lundi_soir"=> $lundi_soir
,":mardi_matin"=> $mardi_matin
, ":mardi_soir" => $mardi_soir
, ":mercredi_matin" => $mercredi_matin
, ":mercredi_soir" => $mercredi_soir
, ":jeudi_matin" => $jeudi_matin
, ":jeudi_soir" => $jeudi_soir
, ":vendredi_matin" => $vendredi_matin
, ":vendredi_soir" => $vendredi_soir);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo '$a_data';
echo "</pre>";
exit();
}
9 févr. 2016 à 16:33
10 févr. 2016 à 10:29
10 févr. 2016 à 10:47
Si tu fais des insertions en BDD sur des tables contenant des clés étrangères... tu dois respecter un certain ordre pour faire tes insertions... et surtout... tes enregistrements doivent exister dans la table avec laquelle tu as la "liaison".
Sans connaitre la structure exacte de tes tables... ni même le code utilisé pour faire tes enregistrements... IMPOSSIBLE de t'aider.
10 févr. 2016 à 10:48
10 févr. 2016 à 10:48