Advertisement
Guest User

Untitled

a guest
May 7th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.72 KB | None | 0 0
  1.       <?php
  2.       if (isset($_POST['submitted'])) {
  3.      
  4.       DEFINE ('DB_USER', 'root');
  5.  
  6.       DEFINE ('DB_PASSWORD', '');
  7.  
  8.       DEFINE ('DB_HOST', 'localhost');
  9.  
  10.       DEFINE ('DB_NAME', 'users');
  11.  
  12.        
  13.  
  14.       $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());
  15.  
  16.        
  17.  
  18.       @mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );
  19.  
  20.  
  21.  
  22.  
  23.        
  24.           $errors = array();
  25.      if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
  26.               $user = mysql_real_escape_string($_POST['username']);
  27.               $query = "SELECT username FROM users WHERE username = '$user'";
  28.               $result = @mysql_query($query);
  29.               $num = @mysql_num_rows($result);
  30.              
  31.               if ($num> 0) {
  32.                   $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
  33.               } else {
  34.                   $username = mysql_real_escape_string($_POST['username']);
  35.               }
  36.           } else {
  37.               $errors[] = '<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
  38.           }
  39.  
  40.  
  41.       if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}', stripslashes(trim($_POST['email'])) )) {
  42.               $errors[] = '<font color="red">Please provide a valid email address.</font>';
  43.           } else {
  44.               $email = mysql_real_escape_string($_POST['email']);
  45.           }
  46.  
  47.       if (!empty($_POST['password1'])) {
  48.               if ($_POST['password1'] != $_POST['password2']) {
  49.                   $errors[] = '<font color="red">The 2 passwords you have entered do not match.</font>';
  50.               } else {
  51.                   $password = $_POST['password1'];
  52.               }
  53.           } else {
  54.                 $errors[] = '<font color="red">Please provide a password.</font>';
  55.           }
  56.  
  57.        if (empty($errors)) {
  58.                        $a = md5(uniqid(rand(), true));
  59.                $query = "INSERT INTO users (username, email, password, active) VALUES ('$username', '$email', MD5('$password'), '$a')";
  60.              
  61.               $result = @mysql_query($query);
  62.              
  63.               if (mysql_affected_rows() == 1) {
  64.              
  65.                        // Show thank you message
  66.                   echo '<h3>Thank You!</h3>
  67.                  You have been registered!';
  68.               } else {
  69.                   echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
  70.               }
  71.       } else {
  72.           echo '<h3>Error!</h3>
  73.              The following error(s) occured:<br />';
  74.              
  75.               foreach ($errors as $msg) {
  76.                   echo " - <font color=\"red\">$msg</font><br />\n";
  77.               }
  78.           }
  79.       }
  80.       ?>
  81.  
  82.  
  83.  
  84.       <h3>Register</h3>
  85.       <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
  86.       <p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlength="30" /> <small>Username</small></p>
  87.       <p><input type="password" name="password1" size="30" maxlength="40" /> <small>Password</small></p>
  88.       <p><input type="password" name="password2" size="30" maxlength="40" /> <small>Confirm Password</small></p>
  89.       <p><input type="text" name="email" size="30" maxlength="30" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /> <small>Email Address</small></p>
  90.       <p><input type="submit" name="submit" value="Register" /></p>
  91.       <input type="hidden" name="submitted" value="TRUE" />
  92.       </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement