Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1.  
  2. <?php
  3.         if($_POST)
  4.         {
  5.             //form validation
  6.             if(empty($_POST['firstName'])||empty($_POST['lastName'])|| empty($_POST['email'])|| empty($_POST['pass'])|| empty($_POST['rePass']))
  7.             {
  8.                 $errors[]='You must fill out all the fields.';
  9.             }
  10.        
  11.            
  12.            
  13.             //password is more than 6 characters
  14.             if(strlen($password)<6){
  15.                 $errors[]='Password must be atleast 6 characters.';
  16.             }
  17.            
  18.            
  19.             if($password!=$confirm){
  20.                 $errors[]='The password does not match.';
  21.             }
  22.            
  23.             //check email exist in database
  24.             $query=$db->query("SELECT * FROM register WHERE email='$email'");
  25.             $user=mysqli_fetch_assoc($query);
  26.             $userCount= mysqli_num_rows($query);
  27.             if($userCount!=0){
  28.                 $errors[]= 'That email has already an account.';
  29.             }
  30.            
  31.             //check for errors
  32.             if(!empty($errors)){
  33.                 echo dispaly_errors($errors);
  34.             }else
  35.                 //log user in
  36.                 {
  37.                     $db->query("INSERT INTO `register` (`firstName`, `lastName`, `moNumber`, `email`, `pass`, `MorF`) VALUES ('$fname','$lname','$num','$email','$new_hashed','$gender')");
  38.                     $_SESSION['success_flash']='Your account has been created!';
  39.                     header('Location: index.php');
  40.                 }
  41.         }
  42.        
  43.     ?>
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. <?php
  68.         require_once 'connect.php';
  69.  
  70.     $fname= ((isset($_POST['firstName']))?sanitize($_POST['firstName']):'');
  71.     $fname=trim($fname);
  72.     $lname= ((isset($_POST['lastName']))?sanitize($_POST['lastName']):'');
  73.     $lname=trim($lname);
  74.     $name= $fname." ".$lname;
  75.     $email= ((isset($_POST['email']))?sanitize($_POST['email']):'');
  76.     $email=trim($email);
  77.     $ph= ((isset($_POST['ph']))?$_POST['ph']:'');
  78.    
  79.     $moNumber= ((isset($_POST['moNumber']))?sanitize($_POST['moNumber']):'');
  80.     $moNumber=trim($moNumber);
  81.    
  82.     $num =  $ph.$moNumber;
  83.     $password= ((isset($_POST['pass']))?sanitize($_POST['pass']):'');
  84.     $password=trim($password);
  85.     $confirm= ((isset($_POST['rePass']))?sanitize($_POST['rePass']):'');
  86.     $confirm=trim($confirm);
  87.     $gender= ((isset($_POST['MorF']))?$_POST['MorF']:'');
  88.     if($gender=="Male")
  89.     {
  90.         $maleck="checked";
  91.         $femaleck="";
  92.         $transck="";
  93.     }
  94.     elseif($gender=="Female"){
  95.         $femaleck="checked";
  96.         $maleck="";
  97.         $transck="";
  98.     }
  99.     else
  100.     {
  101.         $femaleck="";
  102.         $maleck="";
  103.         $transck="checked";
  104.     }
  105.    
  106.     $errors=array();
  107.     $new_hashed= password_hash($password, PASSWORD_DEFAULT);
  108.  
  109. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement