Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <meta charset="utf-8">
  2.  
  3. <?php
  4. if(isset($_POST['submit']))
  5. {
  6. $username = htmlspecialchars(trim($_POST['username']));
  7. $password = htmlspecialchars(trim($_POST['password']));
  8. $repeatpassword = htmlspecialchars(trim($_POST['repeatpassword']));
  9.  
  10. if ($username && $password && $repeatpassword)
  11. {
  12. if (strlen($username) >= 5)
  13. {
  14. if (strlen($password) >= 5)
  15. {
  16. if ($password == $repeatpassword)
  17. {
  18.  
  19. $password = md5($password);
  20.  
  21. try {
  22. $bdd = new PDO('mysql:host=localhost;dbname=phpmembre;charset=utf8', 'root', 'root');
  23. } catch(PDOException $e) {
  24. die($e->getCode() . ' : ' . $e->getMessage());
  25. }
  26.  
  27. try {
  28. $req = $bdd->prepare('INSERT INTO inscription(username,password) VALUES (:username, :password');
  29. $req->execute(array(
  30. 'username' => $username,
  31. 'password' => $password));
  32.  
  33. echo 'Merci ' . $username . ' ! Votre inscription à été prise en compte !';
  34. } catch(PDOException $e) {
  35. die($e->getCode() . ' : ' . $e->getMessage());
  36. }
  37. } else {
  38. echo "Les mots de passe ne sont pas identiques !";
  39. }
  40. } else {
  41. echo "Votre mot de passe est trop court ! Il doit contenir au moins 5 caractères !";
  42. }
  43. } else {
  44. echo "Votre nom d'utilisateur est trop court ! Il doit contenir au moins 5 caractères !";
  45. }
  46. } else {
  47. echo "Veuillez saisir tous les champs !";
  48. }
  49. } ?>
  50.  
  51. <h1>Inscription</h1>
  52. <form method="post" action="register.php">
  53. <p>Votre nom d'utilisateur</p>
  54. <input type="text" name="username">
  55. <p>Votre mot de passe</p>
  56. <input type="password" name="password">
  57. <p>Répetez votre mot de passe</p>
  58. <input type="password" name="repeatpassword"><br />
  59. <input type="submit" name="submit" value="Valider">
  60. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement