Advertisement
Guest User

Untitled

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