Advertisement
Guest User

Untitled

a guest
Apr 4th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['signup-submit'])) {
  3.  
  4.     require 'dbh.inc.php';
  5.  
  6.     $username = $_POST['uid'];
  7.     $email    = $_POST['email'];
  8.     $password = $_POST['pwd'];
  9.     $repeat   = $_POST['pwd-repeat'];
  10.  
  11.     if (empty($username) || empty($email) || empty($password) || empty($repeat)) {
  12.         header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
  13.         exit();
  14.     }
  15.     elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
  16.         header("Location: ../signup.php?error=invalidmailuid&uid");
  17.         exit();
  18.     }
  19.  
  20.     elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  21.         header("Location: ../signup.php?error=invalidmail&uid=".$username);
  22.         exit();
  23.     }
  24.     elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
  25.         header("Location: ../signup.php?error=invaliduid&mail=".$email);
  26.         exit();
  27.     }
  28.     elseif ($password !== $repeat) {
  29.         header("Location: ../signup.php?error=passwordcheckuid=".$username."&mail".$email);
  30.         exit();
  31.     }
  32.     else {
  33.        
  34.         $sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
  35.         $stmt = mysqli_stmt_init($conn);
  36.         if (!mysqli_stmt_prepare($stmt, $sql)) {
  37.             header("Location: ../signup.php?error=sqlerror");
  38.             exit();
  39.         }
  40.         else {
  41.             mysqli_stmt_bind_param($stmt, "s", $username);
  42.             mysqli_stmt_execute($stmt);
  43.             mysqli_stmt_store_result($stmt);
  44.             $resultCheck = mysqli_stmt_num_rows($stmt);
  45.             if ($resultCheck > 0) {
  46.             header("Location: ../signup.php?error=userTaken&mail=".$email);
  47.             exit();
  48.             }
  49.             else {
  50.  
  51.                 $sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?)";
  52.                 $stmt = mysqli_stmt_init($conn);
  53.                 if (!mysqli_stmt_prepare($stmt, $sql)) {
  54.                     header("Location: ../signup.php?error=sqlerror");
  55.                     exit();
  56.                 }
  57.                 else {
  58.                 $hasedPwd = password_hash($password, PASSWORD_DEFAULT);
  59.  
  60.  
  61.                 mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
  62.                 mysqli_stmt_execute($stmt);
  63.                 header("Location: ../signup.php?signup=success");
  64.                 exit();
  65.                 }
  66.             }
  67.         }
  68.  
  69.     }
  70.     mysqli_stmt_close($stmt);
  71.     mysql_close($conn);
  72. }
  73. else {
  74.     header("Location: ../signup.php");
  75.     exit();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement