Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. {<?php
  2.  
  3. include("config.php");
  4.  
  5. $error = "";
  6. $username = "";
  7. $msgGame = "";
  8.  
  9. if($_SERVER["REQUEST_METHOD"] == "POST" AND isset($_POST['back'])) {
  10. header("location: login.php");
  11. }
  12. else if($_SERVER["REQUEST_METHOD"] == "POST") {
  13.  
  14. // username and password sent from form
  15. $username = mysqli_real_escape_string($db,$_POST['username']);
  16. $pass1 = mysqli_real_escape_string($db,$_POST['password1']);
  17. $pass2 = mysqli_real_escape_string($db,$_POST['password2']);
  18.  
  19. //searches for username that is aptemting to register
  20. $sql = "SELECT id FROM users WHERE username = '$username'";
  21. $result = mysqli_query($db,$sql);
  22.  
  23. $count = mysqli_num_rows($result);
  24.  
  25. // If no username not found in database then proceed
  26. if($count == 0) {
  27.  
  28. // Checks if password matches and is at least 6 letters/symbols long
  29. if ($pass1 == $pass2 AND strlen($pass1) > 5){
  30. //encrypts password (twice)
  31. $pass = md5(md5($pass1));
  32. $sql = "INSERT INTO users (username, password) VALUES ('$username', '$pass')";
  33. $result = mysqli_query($db,$sql);
  34. // if registration successful then continue to next page
  35. if ($result){
  36. if (isset($_POST['game'])){
  37. $msgGame = "SUCCESS";
  38. }
  39. else{
  40. header("location: registration_success.php");
  41. }
  42. }else{
  43. $msgGame = "FAIL";
  44. $error = "Could not add user...";
  45. }
  46. }else{
  47. $msgGame = "FAIL";
  48. $error = "Password not matching or too short (min 6 symbols)!! Please try again.";
  49. }
  50. }else {
  51. $msgGame = "FAIL";
  52. $error = "Username <u>". $username."</u> already exists, sorry!";
  53. }
  54.  
  55. // checks is game variable is set
  56. if (isset($_POST['game'])){
  57. // displays msg and and returns
  58. echo $msgGame;
  59. return; // (return aka don't run rest of the code)
  60. }
  61. }
  62. ?>} catch(exception $ex){ echo $ex; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement