Advertisement
Guest User

Untitled

a guest
Dec 30th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <?php
  2. define('HOST','localhost');
  3. define('DB_NAME','kevinsmi_registration');
  4. define('USER','root');
  5. define('PASS','Sp1');
  6.  
  7. try{
  8.  
  9. $db = new PDO("mysql:host=" . HOST . ";dbname=" . DB_NAME, USER, PASS);
  10. global $db;
  11.  
  12. }catch(PDOException $e){
  13.  
  14. echo "An error occured while connecting to MySQL.";
  15.  
  16. }
  17.  
  18. $db_server = 'localhost';
  19. $db_username = 'root';
  20. $db_password = 'Sp1';
  21. $db_name = 'kevinsmi_registration';
  22. $sql = new mysqli($db_server, $db_username, $db_password, $db_name);
  23.  
  24. if(
  25. isset($_POST['form_register'])
  26. ){
  27.  
  28. $username = stripslashes($sql->real_escape_string(strip_tags($_POST['username'])));
  29. $name = stripslashes($sql->real_escape_string(strip_tags($_POST['name'])));
  30. $lastname = stripslashes($sql->real_escape_string(strip_tags($_POST['lastname'])));
  31. $email = stripslashes($sql->real_escape_string(strip_tags($_POST['email'])));
  32. $pass = $_POST['pass'];
  33. $rpass = $_POST['rpass'];
  34.  
  35. // Verify if the user entered all the required informations
  36. if(
  37. !empty($name)
  38. && !empty($lastname)
  39. && !empty($email)
  40. && !empty($pass)
  41. && !empty($rpass)
  42. && $pass == $rpass
  43. && preg_match('/^[a-zA-Z0-9_\\-]{4,24}$/', $username)
  44. ){
  45.  
  46. // Check if the email is already taken
  47. $cEmail = $db->prepare("SELECT * FROM users WHERE email = '$email'");
  48. $cEmail->execute();
  49. $checkEmail = $cEmail->fetch();
  50.  
  51. // Check if the username is already taken
  52. $cUser = $db->prepare("SELECT * FROM users WHERE username = '$username'");
  53. $cUser->execute();
  54. $checkUser = $cUser->fetch();
  55.  
  56. // If they are not taken
  57. if(
  58. $checkEmail !== true
  59. && $checkUser !== true
  60. ){
  61.  
  62. // Password encryption
  63. $options = ['cost' => 12];
  64. $password = password_hash($pass, PASSWORD_BCRYPT, $options);
  65.  
  66. $reg = $db->prepare("INSERT INTO users (username, name, lastname, email, password, role) VALUES (:username, :name, :lastname, :email, :password, :role)");
  67.  
  68.  
  69. $reg->execute([
  70. 'username' => $username,
  71. 'name' => $name,
  72. 'lastname' => $lastname,
  73. 'email' => $email,
  74. 'password' => $password,
  75. 'uuid' => $uuid,
  76. 'role' => 'user',
  77. ]);
  78.  
  79. header('location:?1');
  80.  
  81. }else{
  82. header('location:?2');
  83. }
  84.  
  85. }else{
  86. header('location:?3');
  87. }
  88.  
  89. }
  90.  
  91. ?>
  92.  
  93. <!DOCTYPE html>
  94. <html>
  95. <head>
  96. <title>Book Now - Client Sign Up</title>
  97. <link rel="stylesheet" type="text/css" href="style.css">
  98. <script src="http://cdn.lambocreeper.uk/bootstrap.js"></script>
  99. <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
  100. </head>
  101. <body>
  102.  
  103. <form method="post">
  104. <input type="text" name="username" placeholder="Username"><br>
  105. <input type="text" name="name" placeholder="First Name"><br>
  106. <input type="text" name="lastname" placeholder="Last Name"><br>
  107. <input type="email" name="email" placeholder="Email address"><br>
  108. <input type="password" name="pass" placeholder="Password"><br>
  109. <input type="password" name="rpass" placeholder="Re-password"><br>
  110. <input type="submit" name="form_register" placeholder="Complete registration"><br>
  111. </form>
  112.  
  113. </body>
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement