Advertisement
SemmieBroDo

Untitled

Dec 25th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['submit'])){
  4.  
  5.  
  6. $dbServername = "localhost";
  7. $dbUsername = "root";
  8. $dbPassword = "";
  9. $dbName = "loginsystem";
  10.  
  11. $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
  12.  
  13. /* check connection */
  14. if (mysqli_connect_errno()) {
  15. printf("Connect failed: %s\n", mysqli_connect_error());
  16. exit();
  17. }
  18.  
  19. $first = mysqli_real_escape_string($conn, $_POST['first']);
  20. $last = mysqli_real_escape_string($conn, $_POST['last']);
  21. $email = mysqli_real_escape_string($conn, $_POST['email']);
  22. $uid = mysqli_real_escape_string($conn, $_POST['uid']);
  23. $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
  24.  
  25. //error handlers
  26. //check for empty fields
  27.  
  28. if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)){
  29. header("Location: ../signup.php?signup=empty");
  30. exit();
  31. } else {
  32. //Check if input character are valid
  33. if(!preg_match("/^[a-zA-Z]*$/", $first ) || !preg_match("/^[a-zA-Z]*$/", $last )) {
  34. header("Location: ../signup.php?signup=invalid");
  35. exit();
  36. }else {
  37. //Check if email is valid
  38. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  39. header("Location: ../signup.php?signup=email");
  40. exit();
  41. } else {
  42. $sql = "SELECT * FROM users WHERE user_uid= '$uid'" ;
  43. $result = mysqli_query($conn, $sql);
  44. $resultCheck = mysqli_num_rows($result);
  45.  
  46. if ($resultCheck > 0) {
  47. header("Location: ../signup.php?signup=usertaken");
  48. exit(); {
  49. }
  50. } else {
  51. //Hashing the password
  52. $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  53. $sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ($first, $last, $email, $uid, $pwd);";
  54. mysqli_query($conn, $sql);
  55. } header("Location: ../signup.php?signup=succes");
  56. exit();
  57. }
  58.  
  59.  
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. }else{
  69. header("Location: ../signup.php");
  70. exit();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement