Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. <?php
  2. require 'connect.php'; // Required Connection
  3.  
  4. $username = "";
  5. $email = "";
  6. $password = "";
  7. $joindate = "";
  8. $errorarray = array();
  9.  
  10. if(isset($_POST['register_btn'])){
  11. $username = strip_tags($_POST['username']);
  12. $username = str_replace(' ','',$username);
  13. $username = ucfirst(strtolower($username));
  14. $_SESSION['username'] = $username;
  15.  
  16. $email = strip_tags($_POST['email']);
  17. $email = str_replace(' ','',$email);
  18. $email = ucfirst(strtolower($email));
  19. $_SESSION['email'] = $email;
  20.  
  21. $password = strip_tags($_POST['password']);
  22. $_SESSION['password'] = $password;
  23. $joindate = date("Y-m-d");
  24.  
  25. if(filter_var($username)) {
  26. $checkusername = mysqli_query($connection, "SELECT username FROM users WHERE username='$username'");
  27. $numrows_username = mysqli_num_rows($checkusername);
  28. if($numrows_username > 0) {
  29. array_push($errorarray, "Username already in use!<br>");
  30. }
  31. }
  32.  
  33. if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
  34. $email = filter_var($email, FILTER_VALIDATE_EMAIL);
  35. $checkemail = mysqli_query($connection, "SELECT email FROM users WHERE email='$email'");
  36. $numrows_email = mysqli_num_rows($checkemail);
  37. if($numrows_email > 0) {
  38. array_push($errorarray, "Email already in use!<br>");
  39. }
  40. }
  41.  
  42. if(strlen($username) > 25 || strlen($username) < 5) {
  43. array_push($errorarray, "Your username must be between 5 and 25 characters!<br>");
  44. }
  45.  
  46. if(strlen($password > 30 || strlen($password) < 5)) {
  47. array_push($errorarray, "Your password must be between 5 and 30 characters!<br>");
  48. }
  49.  
  50. if(empty($errorarray)) {
  51. $password = md5($password);
  52. $random_pic = rand(1, 2);
  53. if($random_pic == 1)
  54. $profilepicture = "assets/images/profilepictures/defaults/default1.png";
  55. else if($random_pic == 2)
  56. $profilepicture = "assets/images/profilepictures/defaults/default2.png";
  57.  
  58. $query = mysqli_query($connection, "INSERT INTO users VALUES ('','$username','$email','$password','$joindate','$profilepicture','0','no',',')");
  59. }
  60. }
  61.  
  62.  
  63.  
  64. ?>
  65. <html>
  66. <head>
  67. </head>
  68. <body>
  69. <form action="register.php" method="POST">
  70.  
  71. <?php if(in_array("Username already in use!<br>", $errorarray)) echo "Username already in use!<br>";
  72. else if(in_array("Your username must be between 5 and 25 characters!<br>", $errorarray)) echo "Your username must be between 5 and 25 characters!<br>"
  73. ?>
  74. <input type="text" name="username" placeholder="Username" value="
  75. <?php if(isset($_SESSION['username'])) {
  76. echo $_SESSION['username']; }
  77. ?>"><br>
  78.  
  79. <?php if(in_array("Email already in use!<br>", $errorarray)) echo "Email already in use!<br>";?>
  80. <input type="email" name="email" placeholder="Email" value="
  81. <?php if(isset($_SESSION['email'])) {
  82. echo $_SESSION['email']; }
  83. ?>"><br>
  84.  
  85. <?php if(in_array("Your password must be between 5 and 30 characters!<br>", $errorarray)) echo "Your password must be between 5 and 30 characters!<br>";?>
  86. <input type="password" name="password" placeholder="Password" value="
  87. <?php if(isset($_SESSION['password'])) {
  88. echo $_SESSION['password']; }
  89. ?>"><br>
  90.  
  91. <button type="submit" name="register_btn">Register</button>
  92.  
  93. </form>
  94. </body>
  95. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement