Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.23 KB | None | 0 0
  1. <?php require_once("checklogin.php"); ?>
  2. <?php
  3.     require_once("includes/functions.php");
  4.    
  5.     if(isset($_POST['f_name'], $_POST['l_name'], $_POST['email'], $_POST['user_name'], $_POST['user_pswd'],
  6.              $_POST['user_pswd2'], $_POST['type']))
  7.     {
  8.         require_once("includes/connection.php");
  9.         //real escape all the user entered data
  10.         $f_name = $connection->real_escape_string($_POST['f_name']);
  11.         $l_name = $connection->real_escape_string($_POST['l_name']);
  12.         $email = $connection->real_escape_string($_POST['email']);        
  13.         $user_name = $connection->real_escape_string($_POST['user_name']);
  14.         $user_pswd = $connection->real_escape_string($_POST['user_pswd']);
  15.         $user_pswd2 = $connection->real_escape_string($_POST['user_pswd2']);
  16.         $type = $_POST['type'];
  17.        
  18.         echo $l_name . "<br />" . $email . "<br />";
  19.         //check the amount of rows that matches the username to see if it is taken
  20.         $stmt = $connection->prepare("SELECT COUNT(user_name) AS count
  21.                                     FROM user
  22.                                     WHERE user_name = ?");
  23.        
  24.        
  25.         $stmt->bind_param('s', $user_name);
  26.         $stmt->execute();
  27.         $stmt->bind_result($count); // place the result (count) into this variable
  28.         $stmt->fetch(); //fill the result variable(s) binded
  29.         $stmt->close();
  30.        
  31.         $same = false;
  32.         if($user_pswd == $user_pswd2)
  33.         {
  34.             $same = true;
  35.         }
  36.        
  37.         if(((int)$count == 0) && ($same == true))
  38.         { // username is not taken and there is no password mismatch
  39.             $user_pswd = hashed_pass($user_pswd); // produce hashed password
  40.            
  41.             $query = <<<SQL
  42.         INSERT INTO
  43.                     user
  44.                         (user_type, fname, lname, user_name, user_password,
  45.                         user_email)
  46.                     VALUES
  47.                         ('$type',
  48.                          '$f_name',
  49.                          '$l_name',
  50.                          '$user_name',
  51.                          '$user_pswd',
  52.                          '$email'
  53.             );
  54. SQL;
  55.            
  56.             if(isset($query))
  57.             {
  58.                 $result = $connection->query($query);
  59.                
  60.                 if(!$result)
  61.                 {
  62.                     echo "Error Message: " . $connection->error; // if query failed empty spit out an error
  63.                 }
  64.                 else
  65.                 {
  66.                     header("location: user_add_success.php"); //sent to success page
  67.                     exit();
  68.                 }
  69.             }
  70.            
  71.             $connection->close();
  72.         }
  73.         elseif((int)$count > 0) // if the username is taken
  74.         {
  75.             header("location: taken_username.php"); //sent to error page            
  76.             exit();
  77.         }
  78.         elseif($same == false) // if there is a password mismatch
  79.         {
  80.             header("location: pswd_mismatch.php"); //sent to error page            
  81.             exit();
  82.         }
  83.     }
  84.     else
  85.     {
  86.         header("location: missing_info.php"); //sent back to the Add user page
  87.         exit();
  88.     }
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement