Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.37 KB | None | 0 0
  1. <?php
  2.  
  3.         //Check to see if the form has been submitted
  4.         if(isset($_POST['submit'])){
  5.            
  6.             //protect and then add the posted data to variables
  7.             $username = protect($_POST['username']);
  8.             $password = protect($_POST['password']);
  9.             $password2 = protect($_POST['password2']);
  10.             $email = protect($_POST['email']);
  11.             $permisson = protect ($_POST['permission']);
  12.             $agree = protect ($_POST['agree']);
  13.  
  14.  
  15.             //check to make sure they agree to TOS
  16.             if(!$agree){
  17.                 echo "You must agree to the Terms of Service to sign up";
  18.             }else{
  19.             //check to see if any of the boxes were not filled in
  20.             if(!$username){
  21.                 //if any weren't display the error message
  22.                 echo "<center>You need to fill in a Username!</center>";
  23.             }else{
  24.                 if(!$password){
  25.                 //if any weren't display the error message
  26.                 echo "<center>You need to fill in a password!</center>";
  27.             }else{
  28.                 if(!$password2){
  29.                 //if any weren't display the error message
  30.                 echo "<center>You need to fill in the conformation password!</center>";
  31.             }else{
  32.                 if(!$email){
  33.                 //if any weren't display the error message
  34.                 echo "<center>You need to enter an email adress!</center>";
  35.             }else{
  36.                 if(!$permission){
  37.                 //if any weren't display the error message
  38.                 echo "<center>Select if you are an artist or not!</center>";
  39.             }else{
  40.                 //if all were filled in continue checking
  41.  
  42.                 //Check if the wanted username is more than 32 or less than 3 charcters long
  43.                 if(strlen($username) > 32 || strlen($username) < 3){
  44.                     //if it is display error message
  45.                     echo "<center>Your <b>Username</b> must be between 3 and 32 characters long!</center>";
  46.                 }else{
  47.                     //if not continue checking
  48.  
  49.                     //select all the rows from out users table where the posted username matches the username stored
  50.                     $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");
  51.                     $num = mysql_num_rows($res);
  52.  
  53.                     //check if theres a match
  54.                     if($num == 1){
  55.                         //if yes the username is taken so display error message
  56.                         echo  "<center>The <b>Username</b> you have chosen is already taken!</center>";
  57.                     }else{
  58.                         //otherwise continue checking
  59.  
  60.                         //check if the password is less than 5 or more than 32 characters long
  61.                         if(strlen($password) < 5 || strlen($password) > 32){
  62.                             //if it is display error message
  63.                             echo "<center>Your <b>Password</b> must be between 5 and 32 characters long!</center>";
  64.                         }else{
  65.                             //else continue checking
  66.  
  67.                             //check if the password and confirm password match
  68.                             if($password != $password2){
  69.                                 //if not display error message
  70.                                 echo "<center>The <b>Password</b> you supplied did not math the confirmation password!</center>";
  71.                             }else{
  72.                                 //otherwise continue checking
  73.  
  74.                                 //Set the format we want to check out email address against
  75.                                 $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
  76.  
  77.                                 //check if the formats match
  78.                                 if(!preg_match($checkemail, $email)){
  79.                                     //if not display error message
  80.                                     echo "<center>The <b>E-mail</b> is not valid, must be name@server.tld!</center>";
  81.                                 }else{
  82.                                     //if they do, continue checking
  83.  
  84.                                     //select all rows from our users table where the emails match
  85.                                     $res1 = mysql_query("SELECT * FROM `users` WHERE `email` = '".$email."'");
  86.                                     $num1 = mysql_num_rows($res1);
  87.  
  88.                                     //if the number of matchs is 1
  89.                                     if($num1 == 1){
  90.                                         //the email address supplied is taken so display error message
  91.                                         echo "<center>The <b>E-mail</b> address you supplied is already taken</center>";
  92.                                     }else{
  93.                                         //finally, otherwise register there account
  94.  
  95.                                         //insert the row into the database
  96.                                         //first secure password with md5()
  97.                                         $password = md5($password);
  98.                                         $res2 = mysql_query("INSERT INTO `users` (`username`, `password`, `email`, `permission`) VALUES('".$username."','".$password."','".$email."','".$permission."')");
  99.  
  100.                                         //display the success message
  101.                                         echo "<center>You have successfully registered, please login to access your account!</center>";
  102.                                                 }
  103.                                             }
  104.                                         }
  105.                                     }
  106.                                 }
  107.                             }
  108.                         }
  109.                     }
  110.                 }
  111.             }
  112.         }
  113.     }
  114. }
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement