Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require "conf.incPA.php";
- require "functionsPA.php";
- //require "functionAddClient.php";
- // Sous WAMP (Windows)
- showArray($_POST);
- //Compter le nombre de champs que l'on a, ici on doit en avoir 11
- if( count($_POST) == 13 &&
- !empty($_POST["email"]) &&
- !empty($_POST["pwd"]) &&
- !empty($_POST["pwd2"]) &&
- !empty($_POST["gender"]) &&
- !empty($_POST["name"]) &&
- !empty($_POST["firstname"]) &&
- !empty($_POST["birthday"]) &&
- isset($_POST["phone"]) &&
- !empty($_POST["country"]) &&
- !empty($_POST["legacy"]) &&
- !empty($_POST["captcha"]) &&
- !empty($_POST["adress"]) &&
- isset($_POST["postal_code"]) ){
- $error = false;
- $listOfErrors = [];
- //Vérifier le format de l'email
- if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)){
- $error = true;
- $listOfErrors[]=1;
- }
- //Vérification du mot de passe : min 8 caractères , max 24
- if( strlen($_POST["pwd"]) < 6 || strlen($_POST["pwd"]) > 24){
- $error = true;
- $listOfErrors[]=2;
- }
- //vérification confirmation = mot de passe
- if($_POST["pwd"] != $_POST["pwd2"]){
- $error = true;
- $listOfErrors[]=3;
- }
- //Pour le gender, vérifier le contenu
- //nom : min 2 caractères
- if( strlen($_POST["name"]) < 2){
- $error = true;
- $listOfErrors[]=4;
- }
- //prenom : min 2 caractères
- if( strlen($_POST["firstname"]) < 2){
- $error = true;
- $listOfErrors[]=5;
- }
- //date d'anniversaire : min 18ans max 100ans
- //Est ce que la date est sous cette forme
- //2017-12-31 ou 31/12/2017
- if( substr_count( $_POST["birthday"] , "/")){
- $arrayBirthday = explode("/", $_POST["birthday"]);
- if(count($arrayBirthday) ==3){
- $year = $arrayBirthday[2];
- $month = $arrayBirthday[1];
- $day = $arrayBirthday[0];
- }else{
- $error = true;
- $listOfErrors[]=6;
- }
- }else{
- $arrayBirthday = explode("-", $_POST["birthday"]);
- if(count($arrayBirthday) ==3){
- $year = $arrayBirthday[0];
- $month = $arrayBirthday[1];
- $day = $arrayBirthday[2];
- }else{
- $error = true;
- $listOfErrors[]=7;
- }
- }
- if( isset($year) && isset($month) && isset($day) && checkdate($month, $day, $year)){
- //Entre 18 et 100 ans
- $oneYear = 365*24*60*60;
- $adult=time()-$oneYear*18;
- $old=time()-$oneYear*100;
- $timeBirthday = strtotime($year."-".$month."-".$day);
- if($timeBirthday < $old || $timeBirthday > $adult){
- $error = true;
- $listOfErrors[]=8;
- }
- }else{
- $error = true;
- $listOfErrors[]=9;
- }
- //tel : 0 ou 10 chiffres et que des chiffres
- if( !empty($_POST["phone"])
- && (strlen($_POST["phone"])!=10
- || !is_numeric($_POST["phone"]) ) ){
- $error = true;
- $listOfErrors[]=10;
- }
- //gender : dans notre liste
- //Est ce qu'il exite la clé y dans le tableau
- //$listOfGender
- /*
- if( !array_key_exists($_POST["gender"], $listOfGender) ){
- $error = true;
- }
- if( !array_key_exists($_POST["country"], $listOfCountry) ){
- $error = true;
- }
- */
- if( !isset ( $listOfGender[$_POST["gender"]] ) ){
- $error = true;
- $listOfErrors[]=11;
- }
- if( !isset ( $listOfCountry[$_POST["country"]] ) ){
- $error = true;
- $listOfErrors[]=12;
- }
- if( strtolower($_POST["captcha"]) != $_SESSION["captcha"]){
- $error = true;
- $listOfErrors[]=13;
- }
- if( (strlen($_POST["postal_code"])!=5 || !is_numeric($_POST["postal_code"]) ) ){
- $error = true;
- $listOfErrors[]=14;
- }
- if( strlen($_POST["adress"])>60 ){
- $error = true;
- $listOfErrors[]=15;
- }
- if($error){
- //rediriger l'internaute sur le formulaire
- //print_r($listOfErrors);
- $_SESSION["errors_form"] = $listOfErrors;
- $_SESSION["data_form"] = $_POST;
- header("Location: indexPA.php");
- }else{
- echo "Formulaire OK";
- }
- }else{
- die("Access Denied, we know who you are ".
- $_SERVER["REMOTE_ADDR"]);
- }
- $email = $_POST['email'];
- $motdepasse = $_POST['pwd'];
- $nom = $_POST['name'];
- $prenom = $_POST['firstname'];
- $adresse = $_POST['adress'];
- $numtel = $_POST['phone'];
- $datenaissance = $_POST['birthday'];
- $sexe = $_POST['gender'];
- $con = mysqli_connect("localhost", "root", "", "projet_annuel");
- if (mysqli_connect_errno())
- {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- //mysqli_select_db("projet_annuel");
- mysqli_query($con, 'INSERT INTO client (Email, Motdepasse, Nom, Prenom, Adresse, Numtel, DateNaissance, Sexe) VALUES("$email","$motdepasse","$nom","$prenom","$adresse","$numtel","$datenaissance","$sexe")');
- mysqli_close($con);
- /*
- $bdd = new PDO('mysql:host=localhost;dbname=projet_annuel;charset=utf8', 'root', '');
- $reponse = $bdd->query('SELECT * FROM saveUserPA');
- $donnees = $reponse;
- while ($donnees = $reponse);
- $bdd->exec('INSERT INTO projet_annuel(client) VALUES($email,$motdepasse,$nom,$prenom,$adresse,$numtel,$datenaissance,$sexe,NULL,NULL,NULL)');
- echo 'Bienvenue sur notre site';
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement