SHARE
TWEET

Untitled

a guest May 22nd, 2017 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     // Error management
  3.     ini_set('display_errors', 1);
  4.     error_reporting(E_ALL | E_STRICT);
  5.    
  6.     require('includes/connection.php');
  7.     require('includes/cookie.php');
  8.    
  9.     define('TITLE', 'Register');
  10.     require('template/header.php');
  11.    
  12.     if (!loggedin()) {
  13.    
  14.         if ( isset($_POST['submitted']) ) { // Form is submitted
  15.  
  16.             $problemlist = array();
  17.            
  18.             // Validate firstname
  19.             $firstname = trim($_POST['firstname']);
  20.             if (empty($firstname)) {
  21.                 $problemlist[] = 'First name is empty';
  22.             }
  23.            
  24.             // Validate lastname
  25.             $lastname = trim($_POST['lastname']);
  26.             if (empty($lastname)) {
  27.                 $problemlist[] = 'Last name is empty';
  28.             }
  29.            
  30.             // Validate username
  31.             $username = trim($_POST['username']);
  32.             if (empty($username)) {
  33.                 $problemlist[] = 'Username is empty';
  34.             } else if ( mysql_num_rows(mysql_query("SELECT username FROM users WHERE username='$username'")) != 0 ) {
  35.                 $problemlist[] = 'Username is already taken';
  36.             }
  37.            
  38.             // Validate password
  39.             $password = trim($_POST['password']);
  40.             $password2 = trim($_POST['password2']);
  41.             if ($password != $password2) {
  42.                 $problemlist[] = 'Passwords do not match';
  43.             } elseif (strlen($password) < 6) {
  44.                 $problemlist[] = 'Password must be at least 6 characters';
  45.             }
  46.            
  47.            
  48.             if (!empty($problemlist)) { // Redisplay the form
  49. ?>
  50.  
  51. <?php
  52. echo '<ul id="errorlist">';
  53. foreach ($problemlist as $prob) {
  54.     echo "<li class=\"error\">$prob</li>";
  55. }
  56. echo '</ul>';
  57. ?>
  58.  
  59. <form action="register.php" method="post" id="regform">
  60.     <p>
  61.     <label for="username">First Name:</label>
  62.     <input type="text" name="firstname" size="30" value="<?php echo $_POST['firstname']; ?>" />
  63.     </p>
  64.    
  65.     <p>
  66.     <label for="username">Last Name:</label>
  67.     <input type="text" name="lastname" size="30" value="<?php echo $_POST['lastname']; ?>" />
  68.     </p>
  69.    
  70.     <p>
  71.     <label for="username">Username:</label>
  72.     <input type="text" name="username" size="30" value="<?php echo $_POST['username']; ?>" />
  73.     </p>
  74.    
  75.     <p>
  76.     <label for="password">Password:</label>
  77.     <input type="password" name="password" size="30" />
  78.     </p>
  79.    
  80.     <p>
  81.     <label for="password2">Confirm Password:</label>
  82.     <input type="password" name="password2" size="30" />
  83.     </p>
  84.    
  85.     <input type="submit" name="submit" value="Register" />
  86.     <input type="hidden" name="submitted" value="true" />
  87. </form>
  88.  
  89. <?php
  90.             } else { // Enter data in DB
  91.                
  92.                 $firstname = mysql_real_escape_string($firstname);
  93.                 $lastname = mysql_real_escape_string($lastname);
  94.                 $username = mysql_real_escape_string($username);
  95.                 $password = sha1($password);
  96.                
  97.                 $query = "INSERT INTO users (id, firstname, lastname, username, password)
  98.                         VALUES (0, '$firstname', '$lastname', '$username', '$password')";
  99.                
  100.                 if (@mysql_query($query)) {
  101.                     echo '<p>Successfully registered</p>';
  102.                 } else {
  103.                     echo '<p style="color: red;">Could not execute the query because:<br />' . mysql_error() . '</p>
  104.                         <p>The query being run was: ' . $query . '</p>';
  105.                 }
  106.            
  107.             }
  108.        
  109.         } else { // Form is NOT submitted
  110. ?>
  111.  
  112. <form action="register.php" method="post" id="regform">
  113.     <p>
  114.     <label for="username">First Name:</label>
  115.     <input type="text" name="firstname" size="30" />
  116.     </p>
  117.    
  118.     <p>
  119.     <label for="username">Last Name:</label>
  120.     <input type="text" name="lastname" size="30" />
  121.     </p>
  122.    
  123.     <p>
  124.     <label for="username">Username:</label>
  125.     <input type="text" name="username" size="30" />
  126.     </p>
  127.    
  128.     <p>
  129.     <label for="password">Password:</label>
  130.     <input type="password" name="password" size="30" />
  131.     </p>
  132.    
  133.     <p>
  134.     <label for="password2">Confirm Password:</label>
  135.     <input type="password" name="password2" size="30" />
  136.     </p>
  137.    
  138.     <input type="submit" name="submit" value="Register" />
  139.     <input type="hidden" name="submitted" value="true" />
  140. </form>
  141.  
  142. <?php
  143.         } // End submitted IF
  144.        
  145.     } else {
  146.         echo '<br /><br /><br /><p class="error" style="font-size: 130%">You are already logged in</p><br /><br /><br />';
  147.     }
  148.  
  149.     mysql_close();
  150.    
  151.     require('template/footer.php');
  152. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top