Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Database connect.
- $user_db = ""; //Enter SQL username
- $password_db = ""; //Enter SQL password
- $database = ""; //Enter SQL database
- mysql_connect("localhost", $user_db, $password_db);
- mysql_select_db($database) or die ("Unable to select database");
- //Echo the register form.
- echo '
- <h2>Register an account here!</h2>
- <form method="post">
- Username: <br />
- <input type="text" name="username" value="' . (isset($_POST['username']) ? $_POST['username'] : null) . '" maxlength="32" /><br />
- Password: <br />
- <input type="password" name="password" maxlength="32" /> <input type="password" name="password2" maxlength="32" /><br />
- Email: <br />
- <input type="text" name="email" value="' . (isset($_POST['email']) ? $_POST['email'] : null) . '" maxlength="64" /><br />
- <input type="submit" name="submit" value="Register!" />
- <form>
- ';
- if(isset($_POST['submit'])){
- //Basic registering variables.
- $errors = array();
- $username = isset($_POST['username']) ? $_POST['username'] : null;
- $password = isset($_POST['password']) ? $_POST['password'] : null;
- $password2 = isset($_POST['password2']) ? $_POST['password2'] : null;
- $email = isset($_POST['email']) ? $_POST['email'] : null;
- $user_check = mysql_num_rows(mysql_query("SELECT 1 FROM accounts WHERE login = '" . mysql_real_escape_string($username) . "'"));
- $check_email = mysql_num_rows(mysql_query("SELECT 1 FROM accounts WHERE email = '" . mysql_real_escape_string($email) . "'"));
- //Error checking.
- if(strlen($username) > 32){
- $errors[] = 'Username can not be over 32 characters.';
- }
- if(strlen($password) > 32){
- $errors[] = 'Username can not be over 32 characters.';
- }
- if(strlen($username) < 4){
- $errors[] = 'Username must be 4 characters long or more.';
- }
- if(strlen($password) < 4){
- $errors[] = 'Password must be 4 characters long or more.';
- }
- if($password != $password2){
- $errors[] = 'Passwords entered do not match.';
- }
- if(!preg_match("/^\b[A-Z0-9._-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$\b/i", $email)){
- $errors[] = 'Your e-mail follows an invalid format. Please use example@example.com';
- }
- if (!preg_match("/^[a-zA-Z0-9_-\s]+?$/i", $username)){
- $errors[] = 'Your display name may only contain Letters, numbers, spaces, underscores, and dashes.';
- }
- if (!preg_match("/^[a-zA-Z0-9_-\s]+?$/i", $password)){
- $errors[] = 'Your password may only contain Letters, numbers, spaces, underscores, and dashes.';
- }
- if($user_check > 0){
- $errors [] = 'The username ' . $username . ' is already in use.';
- }
- if($check_email > 0){
- $errors [] = 'The email ' . $email . ' is already in use.';
- }
- if(count($errors) == 0){
- //User has registered successfully!
- echo '<br /><br /><b>Register complete!</b>';
- mysql_query("INSERT INTO accounts (login, password, gm, email)
- VALUES ('" . $username . "', '" . $password . "', 'a', '" . $email . "')");
- } else {
- //User has entered something incorrectly!
- echo '<br /><br /><b>Please correct the following ' . count($errors) . ' errors:</b><br />';
- for($i = 0; $i < count($errors); $i++){
- echo $errors[$i] . '<br />';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement