Advertisement
Isaac18

Sign up php script

Dec 15th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. if(isset($_POST['submit'])){
  2.  
  3.  
  4.         $firstname = $_POST['fname'];
  5.         $lastname = $_POST['lname'];
  6.         $email = $_POST['email'];
  7.         $password = $_POST['password'];
  8.  
  9.         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  10.              $emailErr = "Invalid email format";
  11.         }
  12.  
  13.     $dir = "users/$firstname";
  14.  
  15.     try{
  16.         $sql = 'SELECT COUNT(*) FROM users WHERE email = :email AND password = :password';
  17.         $s = $pdo->prepare($sql);
  18.         $s->bindValue(':email', $email);
  19.         $s->bindValue(':password', $password);
  20.         $s->execute();
  21.  
  22.     }catch(PDOException $e){
  23.         $error  = 'error checking if user already exists' . $e->getMessage();
  24.         include 'error.php';
  25.         exit();
  26.     }
  27.  
  28.     $row = $s->fetch();
  29.  
  30.  
  31.     if ($row[0] > 0) {
  32.         $alreadExists="This user already exists";
  33.         include 'index.php';
  34.     }else{
  35.             try{
  36.             $sql = 'INSERT INTO users SET
  37.             first_name = :first_name,
  38.             last_name = :last_name,
  39.             email = :email,
  40.             password = :password';
  41.             $s = $pdo->prepare($sql);
  42.             $s->bindValue(':first_name', $firstname);
  43.             $s->bindValue(':last_name', $lastname);
  44.             $s->bindValue(':email', $email);
  45.             $s->bindValue(':password', $password);
  46.             $s->execute();
  47.  
  48.         If(!file_exists($dir)){
  49.             $createfolder = mkdir("$dir", 0777);
  50.         }        
  51.        
  52.     }
  53.     catch(PDOException $e){
  54.         $error  = 'error adding user ' . $e->getMessage();
  55.         include 'error.php';
  56.         exit();
  57.     }
  58.     session_start();
  59.     include 'core.php';
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement