Guest User

Untitled

a guest
Dec 4th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2. $connection = mysql_connect('localhost', 'root', '') OR die('mysql_connect error:' . mysql_error());
  3.  
  4. if(isset($_POST['register'])) {
  5.     // set register vars
  6.     $username = $_POST['username'];
  7.     $password = $_POST['password'];
  8.     $password2 = $_POST['password2'];
  9.     $reg_error = array();
  10.    
  11.     // check for reg form errors
  12.     if(strlen($username) == 0) {
  13.         $reg_error["user_exist"] = "Choose a Username!";
  14.     }
  15.    
  16.     if(strlen($username) > 20) {
  17.         $reg_error["user_length"] = "That Username is too long :(";
  18.     }
  19.            
  20.     if($password != $password2) {
  21.         $reg_error["pass_math"] = "Those passwords don't match";
  22.        
  23.         if($password > 40) {
  24.             $reg_error["pass_length"] = "Your password is too long";
  25.         }
  26.     }
  27.    
  28.  
  29.     // no reg form errors? then try to add to the db
  30.     if(!$register_error) {
  31.         mysql_select_db('viip', $connection) OR die('mysql_select_db error:' . mysql_error());
  32.         mysql_query("INSERT INTO users (usernames, passwords) VALUES ('$username', '$password')") OR die('mysql_query:' . mysql_error());
  33.         $registered = TRUE;
  34.         unset($_POST['submit']);
  35.     }
  36. }
  37.  
  38. mysql_close($connection);
  39. ?>
  40.  
  41. <form id="register" name="register" action="/test/register.php" method="post">
  42.     <h2>Register</h2>
  43.  
  44.     <?php
  45.         if(!empty($reg_error)) {
  46.             foreach ($reg_error as $value)
  47.                 echo "<p>$value</p>";
  48.         }
  49.         elseif(isset($registered)) {
  50.             echo "<p>Registration Successful</p>";
  51.         }
  52.     ?>
  53.    
  54.     <p><label>Username<br /><input type="text" name="username" maxlength="20" /></label></p>
  55.     <p><label>Password<br /><input type="text" name="password" maxlength="40" /></label></p>
  56.     <p><label>Password<br /><input type="text" name="password2" maxlength="40" /></label></p>
  57.     <p><input type="submit" name="submit" value="Create Account" /></p>
  58. </form>
Add Comment
Please, Sign In to add comment