Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Prenoult
  5. * Date: 15/11/2016
  6. * Time: 13:18
  7. */
  8.  
  9. // Connexion
  10. $connection = new PDO("mysql:host=localhost;dbname=registration", "root", "root");
  11.  
  12. // Verification des champs du formulaire
  13. if (empty($_POST['id']) || empty($_POST['password']) || empty($_POST['passwordConf']) || empty($_POST['email'])) {
  14. echo "Veuillez renseigner tout les champs<br/>";
  15. } else {
  16. if (strlen($_POST['id']) >= 4) {
  17. if(!checkUsername($_POST['id'])) {
  18. $id = $_POST['id'];
  19. }
  20. else echo "Cet identifiant est indisponible<br/>";
  21. } else echo "Votre identifiant doit contenir au moins 4 caractères.<br/>";
  22. if (strlen($_POST['password']) >= 8) {
  23. $password = $_POST['password'];
  24. } else echo "Votre mot de passe doit contenir au moins 8 caractères.<br/>";
  25. if ($_POST['password'] == $_POST['passwordConf']) {
  26. $passwordConf = $_POST['passwordConf'];
  27. } else echo "Votre confirmation doit être identique.<br/>";
  28. if (strstr($_POST['email'], "@") && strstr($_POST['email'], ".")) {
  29. $email = $_POST['email'];
  30. } else echo "Votre adresse email est invalide.<br/>";
  31. if (count($_POST['music']) >= 2) {
  32. $music = $_POST['music'];
  33. } else echo "Veuillez cocher au moins 2 genres<br/>";
  34. }
  35.  
  36. function checkUsername($username)
  37. {
  38. global $connection;
  39. $res = true;
  40. $query = "SELECT COUNT(*) FROM users WHERE name = ?";
  41. $statement = $connection->prepare($query);
  42. $statement->bindValue(1, $username, PDO::PARAM_STR);
  43. $statement->execute();
  44. if ($statement->fetchAll()[0] != 0) $res = false;
  45. return $res;
  46. }
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement