Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2.     include 'mysql_connect.php';
  3.    
  4.     //Sanitize incoming username and password
  5.     $username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
  6.     $password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
  7.  
  8.     $stmt = $db->prepare("SELECT id FROM `accounts` WHERE username = ?");
  9.    
  10.     $stmt->bind_param('ss', $username);
  11.    
  12.     $stmt->execute();
  13.    
  14.     $stmt->store_result();
  15.    
  16.     if($stmt->num_rows > 0){
  17.    
  18.         echo  "<p>Username already taken</p>";
  19.         exit();
  20.     }
  21.    
  22.     $stmt = $db->prepare("INSERT into `accounts` (username, password, last_login) VALUES (?, md5(?), NOW());");
  23.     if(empty($_POST['username'])){
  24.         echo  "<p>Please enter a username</p>";
  25.         exit();
  26.     }
  27.     if(empty($_POST['password'])){
  28.         echo  "<p>Please enter a password</p>";
  29.         exit();
  30.     }
  31.     //Bind the input parameters to the prepared statement
  32.     $stmt->bind_param('ss', $username, $password);
  33.  
  34.     //Execute the query
  35.     $stmt->execute();
  36.  
  37.     session_start();
  38.     $_SESSION['username'] = $username;
  39.            
  40.         //Redirect the user to the home page
  41.         header('Location: SCPB_Home.html');
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement