Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. session_start();
  2. //check if logged in
  3. if (isset($_SESSION['id'])){
  4. header("Location: index.php");
  5. }
  6.  
  7. if (isset($_POST['register'])){
  8. include_once("db.php");
  9.  
  10. $username = strip_tags($_POST['username']);
  11. $password = strip_tags($_POST['password']);
  12. $password_confirm = strip_tags($_POST['password_confirm']);
  13. $email = strip_tags($_POST['email']);
  14.  
  15. $username = stripslashes($username);
  16. $password = stripslashes($password);
  17. $password_confirm = stripslashes($password_confirm);
  18. $email = stripslashes($email);
  19.  
  20. $username = mysqli_real_escape_string($db, $username);
  21. $password = mysqli_real_escape_string($db, $password);
  22. $password_confirm = mysqli_real_escape_string($db, $password_confirm);
  23. $email = mysqli_real_escape_string($db, $email);
  24.  
  25. //encrypt the password
  26. $password = md5($password);
  27. $password_confirm = md5($password_confirm);
  28.  
  29. //sql storage queries
  30. $sql_store = "INSERT into users (username, password, email) VALUES ('$username','$password','$email')";
  31. $sql_fetch_username = "SELECT username FROM users WHERE username='$username'";
  32. $sql_fetch_email = "SELECT email FROM users WHERE email='$email'";
  33. //setting up queries
  34. $query_username = mysqli_query($db, $sql_fetch_username);
  35. $query_email = mysqli_query($db, $sql_fetch_email);
  36.  
  37. //check for matches, incomplete entry, errors or for email already in use
  38. if(mysqli_num_rows($query_username)){
  39. echo"There is already a user with that name!";
  40. return;
  41. }
  42.  
  43. if($username == ""){
  44. echo"Please enter a username!";
  45. return;
  46. }
  47.  
  48. if($password == "" || $password_confirm==""){
  49. echo"Please enter your password!";
  50. return;
  51. }
  52.  
  53.  
  54. if($password !=$password_confirm){
  55. echo"The passwords do not match!";
  56. return;
  57. }
  58.  
  59.  
  60. if (!filter_var($email, FILTER_VALIDATE_EMAIL) || $email ==""){
  61. echo"This email is not valid!";
  62. return;
  63. }
  64.  
  65. if (mysqli_num_rows($query_email)){
  66. echo"That email is already in use!";
  67. return;
  68. }
  69.  
  70. mysqli_query($db, $sql_store);
  71. header("Location: index.php");
  72. ?>
  73.  
  74.  
  75. <!DOCTYPE html>
  76. <html>
  77. <head>
  78. <title>PQ</title>
  79. <link rel="stylesheet" type="text/css" href="style.css">
  80. <script src="main.js"></script>
  81. </head>
  82.  
  83. <body>
  84. <div data-role="page" id="Welcome">
  85. <div data-role="header">
  86. <h1>Welcome</h1>
  87. </div>
  88. <div role="main" id="loginform">
  89. <form method="post" action="register.php" enctype="multipart/form-data">
  90. <input name="username" placeholder="Username" type="text">
  91. <input name="password" placeholder="Password" type="password">
  92. <input name="password_confirm" placeholder="Confirm Password" type="password">
  93. <input name="email" placeholder="Email address" type="text">
  94. <input name="register" type="submit" value="Register">
  95. </form>
  96. </div>
  97. <div data-role="footer" data-position="fixed" data-theme="c">
  98. <h4>(C) 2016</h4>
  99. </div>
  100. </div>
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement