Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require "conf.incPA.php";
  4. require "functionsPA.php";
  5. //require "functionAddClient.php";
  6.  
  7. // Sous WAMP (Windows)
  8.  
  9.  
  10.  
  11.  
  12. showArray($_POST);
  13.  
  14.  
  15.  
  16. //Compter le nombre de champs que l'on a, ici on doit en avoir 11
  17. if( count($_POST) == 13 &&
  18. !empty($_POST["email"]) &&
  19. !empty($_POST["pwd"]) &&
  20. !empty($_POST["pwd2"]) &&
  21. !empty($_POST["gender"]) &&
  22. !empty($_POST["name"]) &&
  23. !empty($_POST["firstname"]) &&
  24. !empty($_POST["birthday"]) &&
  25. isset($_POST["phone"]) &&
  26. !empty($_POST["country"]) &&
  27. !empty($_POST["legacy"]) &&
  28. !empty($_POST["captcha"]) &&
  29. !empty($_POST["adress"]) &&
  30. isset($_POST["postal_code"]) ){
  31.  
  32. $error = false;
  33. $listOfErrors = [];
  34.  
  35. //Vérifier le format de l'email
  36. if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)){
  37. $error = true;
  38. $listOfErrors[]=1;
  39. }
  40.  
  41. //Vérification du mot de passe : min 8 caractères , max 24
  42. if( strlen($_POST["pwd"]) < 6 || strlen($_POST["pwd"]) > 24){
  43. $error = true;
  44. $listOfErrors[]=2;
  45. }
  46. //vérification confirmation = mot de passe
  47. if($_POST["pwd"] != $_POST["pwd2"]){
  48. $error = true;
  49. $listOfErrors[]=3;
  50. }
  51.  
  52. //Pour le gender, vérifier le contenu
  53.  
  54. //nom : min 2 caractères
  55. if( strlen($_POST["name"]) < 2){
  56. $error = true;
  57. $listOfErrors[]=4;
  58. }
  59. //prenom : min 2 caractères
  60. if( strlen($_POST["firstname"]) < 2){
  61. $error = true;
  62. $listOfErrors[]=5;
  63. }
  64.  
  65. //date d'anniversaire : min 18ans max 100ans
  66. //Est ce que la date est sous cette forme
  67. //2017-12-31 ou 31/12/2017
  68. if( substr_count( $_POST["birthday"] , "/")){
  69. $arrayBirthday = explode("/", $_POST["birthday"]);
  70. if(count($arrayBirthday) ==3){
  71. $year = $arrayBirthday[2];
  72. $month = $arrayBirthday[1];
  73. $day = $arrayBirthday[0];
  74. }else{
  75. $error = true;
  76. $listOfErrors[]=6;
  77. }
  78.  
  79. }else{
  80. $arrayBirthday = explode("-", $_POST["birthday"]);
  81. if(count($arrayBirthday) ==3){
  82. $year = $arrayBirthday[0];
  83. $month = $arrayBirthday[1];
  84. $day = $arrayBirthday[2];
  85. }else{
  86. $error = true;
  87. $listOfErrors[]=7;
  88. }
  89.  
  90. }
  91.  
  92. if( isset($year) && isset($month) && isset($day) && checkdate($month, $day, $year)){
  93.  
  94. //Entre 18 et 100 ans
  95. $oneYear = 365*24*60*60;
  96. $adult=time()-$oneYear*18;
  97. $old=time()-$oneYear*100;
  98.  
  99. $timeBirthday = strtotime($year."-".$month."-".$day);
  100.  
  101. if($timeBirthday < $old || $timeBirthday > $adult){
  102. $error = true;
  103. $listOfErrors[]=8;
  104. }
  105.  
  106.  
  107. }else{
  108. $error = true;
  109. $listOfErrors[]=9;
  110. }
  111.  
  112.  
  113. //tel : 0 ou 10 chiffres et que des chiffres
  114. if( !empty($_POST["phone"])
  115. && (strlen($_POST["phone"])!=10
  116. || !is_numeric($_POST["phone"]) ) ){
  117. $error = true;
  118. $listOfErrors[]=10;
  119. }
  120.  
  121. //gender : dans notre liste
  122.  
  123. //Est ce qu'il exite la clé y dans le tableau
  124. //$listOfGender
  125. /*
  126. if( !array_key_exists($_POST["gender"], $listOfGender) ){
  127. $error = true;
  128. }
  129.  
  130. if( !array_key_exists($_POST["country"], $listOfCountry) ){
  131. $error = true;
  132. }
  133. */
  134.  
  135. if( !isset ( $listOfGender[$_POST["gender"]] ) ){
  136. $error = true;
  137. $listOfErrors[]=11;
  138. }
  139.  
  140.  
  141. if( !isset ( $listOfCountry[$_POST["country"]] ) ){
  142. $error = true;
  143. $listOfErrors[]=12;
  144. }
  145.  
  146.  
  147.  
  148. if( strtolower($_POST["captcha"]) != $_SESSION["captcha"]){
  149. $error = true;
  150. $listOfErrors[]=13;
  151. }
  152.  
  153. if( (strlen($_POST["postal_code"])!=5 || !is_numeric($_POST["postal_code"]) ) ){
  154. $error = true;
  155. $listOfErrors[]=14;
  156. }
  157.  
  158. if( strlen($_POST["adress"])>60 ){
  159. $error = true;
  160. $listOfErrors[]=15;
  161. }
  162.  
  163. if($error){
  164. //rediriger l'internaute sur le formulaire
  165. //print_r($listOfErrors);
  166. $_SESSION["errors_form"] = $listOfErrors;
  167. $_SESSION["data_form"] = $_POST;
  168.  
  169. header("Location: indexPA.php");
  170. }else{
  171. echo "Formulaire OK";
  172. }
  173.  
  174.  
  175.  
  176. }else{
  177. die("Access Denied, we know who you are ".
  178. $_SERVER["REMOTE_ADDR"]);
  179. }
  180.  
  181. $email = $_POST['email'];
  182. $motdepasse = $_POST['pwd'];
  183. $nom = $_POST['name'];
  184. $prenom = $_POST['firstname'];
  185. $adresse = $_POST['adress'];
  186. $numtel = $_POST['phone'];
  187. $datenaissance = $_POST['birthday'];
  188. $sexe = $_POST['gender'];
  189.  
  190.  
  191.  
  192. $con = mysqli_connect("localhost", "root", "", "projet_annuel");
  193. if (mysqli_connect_errno())
  194. {
  195. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  196. }
  197.  
  198. //mysqli_select_db("projet_annuel");
  199.  
  200. mysqli_query($con, 'INSERT INTO client (Email, Motdepasse, Nom, Prenom, Adresse, Numtel, DateNaissance, Sexe) VALUES("$email","$motdepasse","$nom","$prenom","$adresse","$numtel","$datenaissance","$sexe")');
  201.  
  202.  
  203. mysqli_close($con);
  204.  
  205.  
  206.  
  207. /*
  208. $bdd = new PDO('mysql:host=localhost;dbname=projet_annuel;charset=utf8', 'root', '');
  209. $reponse = $bdd->query('SELECT * FROM saveUserPA');
  210. $donnees = $reponse;
  211. while ($donnees = $reponse);
  212.  
  213. $bdd->exec('INSERT INTO projet_annuel(client) VALUES($email,$motdepasse,$nom,$prenom,$adresse,$numtel,$datenaissance,$sexe,NULL,NULL,NULL)');
  214.  
  215. echo 'Bienvenue sur notre site';
  216. */
  217.  
  218. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement