Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. <?php
  2.  
  3. $dbServername = "localhost";
  4. $dbUsername = "root";
  5. $dbPassword = "root";
  6. $dbName = "Login System";
  7.  
  8. $con = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
  9.  
  10. <?php
  11.  
  12. if (isset($_POST['submit'])) {
  13.  
  14. include_once 'dbh.inc.php';
  15.  
  16. $first = mysqli_real_escape_string($conn, $_POST['first']);
  17. $last = mysqli_real_escape_string($conn, $_POST['last']);
  18. $email = mysqli_real_escape_string($conn, $_POST['email']);
  19. $uid = mysqli_real_escape_string($conn, $_POST['uid']);
  20. $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
  21.  
  22. //Error handlers
  23. //Check for empty fields
  24. if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
  25. echo <h2>Please fill in all fields;
  26. exit ();
  27. } else {
  28. //Check if input characters are valid
  29. if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
  30. header("Location: ../signup.php?signup=invalid");
  31. exit();
  32. } else {
  33. //Check if email is valid
  34. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  35. header("Location: ../signup.php?signup=email");
  36. exit();
  37. } else {
  38. $sql = "SELECT * FROM users WHERE user_uid='$uid'";
  39. $result = mysqli_query($conn, $sql);
  40. $resultCheck = mysqli_num_rows($result);
  41.  
  42. if ($resultCheck > 0) {
  43. header("Location: ../signup.php?signup=usertaken");
  44. exit();
  45. } else {
  46. //Hashing the password
  47. $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  48. //Insert the user into the database
  49. $sql = "INSERT INTO users (first, last, email, uid, pwd) VALUES ('$first', '$last', '$email', '$uid', '$hashedPwd');";
  50. mysqli_query($conn, $sql);
  51. header("Location: ../signup.php?signup=success");
  52. exit();
  53. }
  54. }
  55. }
  56. }
  57.  
  58. } else {
  59. header("Location: ../signup.php");
  60. exit();
  61. }
  62.  
  63. ?>
  64.  
  65. <?php
  66. include_once 'header.php';
  67. ?>
  68.  
  69. <section class="main-container">
  70. <div class="main-wrapper">
  71. <h2>Signup</h2>
  72. <form class="signup-form" action="includes/signup.inc.php" method="POST">
  73. <input type="text" name="first" placeholder="Firstname">
  74. <input type="text" name="last" placeholder="Lastname">
  75. <input type="text" name="email" placeholder="E-mail">
  76. <input type="text" name="uid" placeholder="Username">
  77. <input type="password" name="pwd" placeholder="Password">
  78. <Button type="submit" name="submit">Sign up</Button>
  79. </form>
  80.  
  81. </div>
  82. </section>
  83.  
  84. <?php
  85. include_once 'footer.php';
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement