Advertisement
Guest User

sssss

a guest
Jul 14th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. if (isset($_POST['registerBtn'])){
  2. $username = preg_replace("/[^A-Za-z0-9-]/","", $_POST['username']);
  3. $password = $_POST['password'];
  4. $rpassword = $_POST['rpassword'];
  5. $email = $_POST['email'];
  6. $errors = array();
  7. $checkUsername0 = $odb -> prepare("SELECT * FROM `users` WHERE `username`='".$username."'");
  8. $checkUsername0 -> execute();
  9. $countUsername0 = $checkUsername0 -> rowCount();
  10. if ($countUsername0 != 0)
  11. {
  12. $errors[] = 'Username is already taken';
  13. }
  14. if (empty($username) || empty($password) || empty($rpassword) || empty($email))
  15. {
  16. $errors[] = 'Please fill in all fields';
  17. }
  18. if ($password != $rpassword)
  19. {
  20. $errors[] = 'Passwords do not match';
  21. }
  22. if (empty($errors))
  23. {
  24. $insertUser = $odb -> prepare("INSERT INTO `users` VALUES(NULL, :username, :password, :email, 0, 0, 0, 0, '', 0)");
  25. $insertUser -> execute(array(':username' => $username, ':password' => SHA1($password), ':email' => $email));
  26. echo '<div class="message" id="message"><p><strong>SUCCESS: </strong>User has been registered. Redirecting....</p></div><meta http-equiv="refresh" content="3;url=login.php">';
  27. }
  28. else
  29. {
  30. echo '<div class="error" id="message"><p><strong>ERROR:</strong><br />';
  31. foreach($errors as $error)
  32. {
  33. echo '-'.$error.'<br />';
  34. }
  35. echo '</div>';
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement