Guest User

stack1

a guest
Aug 7th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. <?php
  2. $reg = @$_POST['reg'];
  3. //declaring variables to prevent errors
  4. $fn = ""; //First Name
  5. $ln = ""; //Last Name
  6. $un = ""; //Username
  7. $em = ""; //Email
  8. $em2 = ""; //Email 2
  9. $pswd = ""; //Password
  10. $pswd2 = ""; // Password 2
  11. $d = ""; // Sign up Date
  12. $u_check = ""; // Check if username exists
  13. //registration form
  14. $fn = strip_tags(@$_POST['fname']);
  15. $ln = strip_tags(@$_POST['lname']);
  16. $un = strip_tags(@$_POST['uname']);
  17. $em = strip_tags(@$_POST['email']);
  18. $em2 = strip_tags(@$_POST['email2']);
  19. $pswd = strip_tags(@$_POST['password']);
  20. $pswd2 = strip_tags(@$_POST['password2']);
  21. $d = date("Y-m-d"); // Year - Month - Day
  22.  
  23. if ($reg) {
  24. if ($em==$em2) {
  25. // Check if user already exists
  26.  
  27. //create a database connection here :
  28. $servername = "localhost";
  29. $username = "username";
  30. $password = "password";
  31. $dbname = "giveyourdatabasenamehere";
  32.  
  33. // Create new database connection
  34. $conn = mysqli_connect($servername, $username, $password, $dbname);
  35. // Check connection
  36.  
  37. $sql = "SELECT username FROM users WHERE username='$un'";
  38.  
  39. $u_check = mysqli_query($conn, $sql);
  40. // Count the amount of rows where username = $un
  41. $check = mysqli_num_rows($u_check);
  42. //Check whether Email already exists in the database
  43. $query2="SELECT email FROM users WHERE email='$em'";
  44. $e_check = mysqli_query($con,$query2);
  45. //Count the number of rows returned
  46. $email_check = mysqli_num_rows($e_check);
  47. if ($check == 0) {
  48. if ($email_check == 0) {
  49. //check all of the fields have been filed in
  50. if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2) {
  51. // check that passwords match
  52. if ($pswd==$pswd2) {
  53. // check the maximum length of username/first name/last name does not exceed 25 characters
  54. if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) {
  55. echo "The maximum limit for username/first name/last name is 25 characters!";
  56. }
  57. else
  58. {
  59. // check the maximum length of password does not exceed 25 characters and is not less than 5 characters
  60. if (strlen($pswd)>30||strlen($pswd)<5) {
  61. echo "Your password must be between 5 and 30 characters long!";
  62. }
  63. else
  64. {
  65. //encrypt password and password 2 using md5 before sending to database
  66. $pswd = md5($pswd);
  67. $pswd2 = md5($pswd2);
  68. $query = mysqli_query($conn,"INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0','Write something about yourself.','','','no')");
  69. die("<h2>Welcome to the HoogleyBoogley Network</h2>Login to your account to get started ...");
  70. }
  71. }
  72. }
  73. else {
  74. echo "Your passwords don't match!";
  75. }
  76. }
  77. else
  78. {
  79. echo "Please fill in all of the fields";
  80. }
  81. }
  82. else
  83. {
  84. echo "Sorry, but it looks like someone has already used that email!";
  85. }
  86. }
  87. else
  88. {
  89. echo "Username already taken ...";
  90. }
  91. }
  92. else {
  93. echo "Your E-mails don't match!";
  94. }
  95. }
  96. ?>
Add Comment
Please, Sign In to add comment