Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.97 KB | None | 0 0
  1. <?php
  2.    // This function tests whether the email address is valid  
  3.     function isValidEmail($email)
  4.     {
  5.         $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
  6.      
  7.         if (eregi($pattern, $email)
  8.             return true;
  9.         else  
  10.             return false;    
  11.     }
  12. ?>
  13.  
  14. <div id="content">
  15. <div id="container">   
  16.     <?php
  17.         if ($_POST[verify] != "true")
  18.         {
  19.     ?>
  20.    
  21.     <div id="content-top" style="font-size: 20; padding-left: 20px;">Create an Account</div><br />
  22.    
  23.     <form action="" method="post" style="padding-left: 20px; padding-bottom: 30px;" name="register">
  24.         <input type="text" value="Username.." name="username" onClick="this.value = ''" class="register"><br /><br />
  25.         <input type="text" value="Password.." name="password" onClick="this.type = 'password'; this.value = ''";
  26.             class="register"><br /><br />
  27.         <input type="text" value="Confirm your password.." name="confirm" onClick="this.type = 'password'; this.value = ''";
  28.             class="register"><br /><br />
  29.         <input type="text" value="Email.." name="email" onClick="this.value = ''" class="register"><br /><br />
  30.         <select name="flags" class="register">
  31.             <option value="24">Wrath of the Lich King</option>
  32.             <option value="12">Burning Crusade</option>
  33.             <option value="0">Classic</option>
  34.         </select><br /><br />
  35.         <select name="forceLanguage" class="register">
  36.             <option value="enGB">English (UK)</option>
  37.             <option value="enUS">English (US)</option>
  38.         </select><br /><br />
  39.         <input type="hidden" name="verify" value="true">
  40.         <input type="submit" value="Create Account" class="submit-register">
  41.     </form>
  42.    
  43.     <?php
  44.         } else {
  45.        
  46.         $username = $_POST[username];
  47.         $password = $_POST[password];
  48.         $confirm = $_POST[confirm];
  49.         $email = $_POST[email];
  50.         $flags = $_POST[flags];
  51.         $forceLanguage = $_POST[forceLanguage];
  52.         $banned = 0;
  53.         $muted = 0;
  54.         mysql_select_db("character", $con);
  55.        
  56.         if ($username == null)                          // check if nothing was put into the username field
  57.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>Username field was empty!</div><br />";
  58.         elseif ($password == null)                      // check if nothing was put into the password field
  59.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>Password field was empty!</div><br />";
  60.         elseif ($confirm == null)                       // check if nothing was put into the confirm password field
  61.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>Confirm your password field was empty!</div><br />";
  62.         elseif ($email == null)                         // check if nothing was put into the email field
  63.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>Email field was empty!</div><br />";
  64.        
  65.                 // None of the inputs are blank, so we can now continue validating it
  66.         $UsernameCheck = mysql_query("SELECT login FROM accounts WHERE login = '$username'");
  67.         $EmailCheck = mysql_query("SELECT email FROM accounts WHERE email = '$email'");
  68.        
  69.         elseif (mysql_num_rows($UsernameCheck) == 1)    // check if username is already taken
  70.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>That username is taken!</div><br />";
  71.         elseif (!IsValidEmail($email))                  // check if the email is a valid email
  72.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>The email you entered was invalid!</div><br />";
  73.         elseif (mysql_num_rows($EmailCheck) == 1)       // check if the email is already taken
  74.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>That email has already been used!</div><br />";
  75.         else
  76.         {
  77.             // the form is valid, and we can now create the account
  78.             mysql_query("INSERT INTO accounts ('login', 'password', 'banned', 'email', 'flags', 'forceLanguage', 'muted')
  79.                 VALUES ('$username', '$password', '$banned', '$email', '$flags', '$forceLanguage', 'muted')");
  80.             echo "<div id='content-top' style='font-size: 20; padding-left: 20px;'>Your account has been created<br />You may
  81.             now log in</div><br />";
  82.         }
  83.        
  84.         }
  85.     ?>
  86. </div>
  87. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement