SHARE
TWEET

Untitled

a guest Jul 17th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (isset($_POST['submit'])){
  2. include_once 'dbh.inc.php';
  3.   $username = mysqli_real_escape_string($conn, $_POST['username']);
  4.   $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
  5.   $email = mysqli_real_escape_string($conn, $_POST['email']);
  6. if(empty($username) || empty($pwd) || empty($email)){
  7.   echo "Fill in all Fields!";
  8. }else {
  9.    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  10.      echo "Email is invalid!";
  11.    }else{
  12.       $stmt = $conn->prepare("SELECT * FROM users WHERE username=?");
  13.       $stmt->bind_param("s", $uid);
  14.       $uid = $username;
  15.       $stmt->execute();
  16.       $result = $stmt->get_result();
  17.       $usernamecheck = mysqli_num_rows($result);
  18.       $rowNum = $result->num_rows;
  19.     if($rowNum > 0){
  20.         echo "Username is taken!";
  21.     }else{
  22.         $stmt = $conn->prepare("SELECT * FROM users WHERE email=?");
  23.         $stmt->bind_param("s", $uemail);
  24.         $uemail = $email;
  25.         $stmt->execute();
  26.         $result = $stmt->get_result();
  27.         $usernamecheck = mysqli_num_rows($result);
  28.         $rowNum = $result->num_rows;
  29.     if($rowNum > 0){
  30.         echo "Email is taken";
  31.     }else{
  32.         $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  33.         $stmt = $conn->prepare("INSERT INTO users (username, pwd, email) VALUES (?, ?, ?)");
  34.     $stmt->bind_param("sss",$uid, $password, $theemail);
  35.     $uid = $username;
  36.     $password = $hashedPwd;
  37.     $theemail= $email;
  38.     $stmt->execute();
  39.     $result = $stmt->get_result();
  40.     header("location: ../user-login.php");
  41.         }
  42.         }
  43.      }
  44.     }
  45.  }else{
  46. header("location: ../user-signup.php");
  47. exit();
  48. }
  49.    
  50. include_once '../dbh.inc.php';
  51. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  52. $username = $_POST['username'];
  53. $email = $_POST['email'];
  54. $pwd = $_POST['pwd'];
  55. if(empty($username) || empty($pwd) || empty($email)){
  56.   echo "Fill in all Fields!";
  57.   exit();
  58. }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  59.      echo "Email is invalid!";
  60.      exit();
  61.    }else{
  62. $chk = "SELECT * FROM user WHERE email='$email'";
  63. $result = mysqli_query($conn, $chk);
  64. while ($row = mysqli_fetch_array($result)) {
  65.   if ($row['email'] == $email) {
  66.     echo "Email Match";
  67.   exit();
  68.   } else {
  69.    $chk = "SELECT * FROM user WHERE username='$username'";
  70.    $result = mysqli_query($conn, $chk);
  71.    while ($row = mysqli_fetch_array($result)) {
  72.     if ($row['username'] == $username) {
  73.     echo "Username Match";
  74.     exit();
  75.   } else {
  76. $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
  77. $join = sprintf("INSERT INTO user(username, email, password) " .
  78.     "VALUES ('%s', '%s', '%s', '%s'); ",
  79.   mysqli_real_escape_string($conn, $username),
  80.   mysqli_real_escape_string($conn, $email),
  81.   mysqli_real_escape_string($conn, $hashedPwd),
  82.   mysqli_insert_id($conn));
  83.   if (mysqli_query($conn, $join)) {
  84.     $i = "joined";
  85.   } else {
  86.     $i = "failed to join";
  87.   }
  88.   echo $i;
  89.   }
RAW Paste Data
Top