Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['submit'])) {
  3. $dbServername = "localhost";
  4. $dbUsername = "root";
  5. $dbPassword = "12345";
  6. $dbName = "loginsystem";
  7.  
  8. $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
  9.  
  10.  
  11. $email = mysqli_real_escape_string($conn, $_POST['email']);
  12. $uid = mysqli_real_escape_string($conn, $_POST['felhasznalonev']);
  13. $pwd = mysqli_real_escape_string($conn, $_POST['jelszo']);
  14. $age = mysqli_real_escape_string($conn, $_POST['eletkor']);
  15. $nem= mysqli_real_escape_string($conn, $_POST['nem']);
  16.  
  17. if (empty($email) || empty($uid) || empty($pwd) || empty($age) || empty($nem)) {
  18. header("Location: ../signuppage.php?signup=empty");
  19. exit();
  20. } else {
  21. if (!preg_match("/^[a-zA-Z]*$/", $uid)) {
  22. header("Location: ../signuppage.php?signup=invalid");
  23. exit();
  24. } else {
  25.  
  26.  
  27. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  28. header("Location: ../signuppage.php?signup=email");
  29. exit();
  30. } else {
  31. $sql = "SELECT * FROM users WHERE user_uid=?";
  32. $stmt = mysqli_stmt_init($conn);
  33. if(!mysqli_stmt_prepare($stmt, $sql)) {
  34. header("Location: ../index.php?login=error");
  35. exit();
  36. } else {
  37. mysqli_stmt_bind_param($stmt, "s", $uid);
  38.  
  39.  
  40. mysqli_stmt_execute($stmt);
  41.  
  42.  
  43. mysqli_stmt_store_result($stmt);
  44. $resultCheck = mysqli_stmt_num_rows($stmt);
  45. if ($resultCheck > 0) {
  46. header("Location: ../signuppage.php?signup=usertaken");
  47. exit();
  48. } else {
  49. $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  50.  
  51. $sql = "INSERT INTO users (user_email, user_uid, user_pwd, user_age, user_nem)
  52. VALUES ('?', '?', '?', '?', '?');";
  53.  
  54. $stmt2 = mysqli_stmt_init($conn);
  55. if(!mysqli_stmt_prepare($stmt2, $sql)) {
  56. header("Location: ../index.php?login=error");
  57. exit();
  58. } else {
  59.  
  60. mysqli_stmt_bind_param($stmt2, "sssss", $email, $uid, $hashedPwd, $age, $nem);
  61.  
  62.  
  63. mysqli_stmt_execute($stmt2);
  64. header("Location: ../signuppage.php?signup=success");
  65.  
  66. exit();
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73.  
  74.  
  75. mysqli_stmt_close($stmt);
  76.  
  77. mysqli_stmt_close($stmt2);
  78.  
  79. } else {
  80. header("Location: ../signuppage.php");
  81. exit();
  82. }
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement