Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <?php # search.inc.php
  2.  
  3. // Redirect if this page was accessed directly:
  4. if (!defined('BASE_URL')) {
  5.  
  6.     // Need the BASE_URL, defined in the config file:
  7.     require_once ('../includes/config.inc.php');
  8.    
  9.     // Redirect to the index page:
  10.     $url = BASE_URL . 'index.php?p=reg';
  11.  
  12.     header ("Location: $url");
  13.     exit;
  14.    
  15. } // End of defined() IF.
  16.  
  17.  
  18. echo '<h2>Welcome to the register page!</h2>';
  19.  
  20.     if($_POST) {
  21.         $password = $_POST['password'];
  22.         $confirm = $_POST['confirm'];
  23.         if($password != $confirm) { ?>
  24. <span style='color:red'>Error: Passwords do not match!</span>
  25. <?php   } else {
  26.             mysql_select_db($dbname);
  27.             $query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')",
  28.                 mysql_real_escape_string($_POST['username']));
  29.             $result = mysql_query($query);
  30.             list($count) = mysql_fetch_row($result);
  31.             if($count >= 1) {
  32. ?>
  33.  
  34. <span style='color:red'>Error: that username is taken.</span>
  35. <?php       } else {
  36.                 $query = sprintf("INSERT INTO users(username,password) VALUES ('%s','%s');",
  37.                     mysql_real_escape_string($_POST['username']),
  38.                     mysql_real_escape_string(md5($password)));
  39.                 mysql_query($query);
  40.             ?>
  41. <span style='color:green'>Congratulations, you registered successfully!</span>
  42. <?php
  43.             }  
  44.         }
  45.     }
  46.  
  47.  
  48.  
  49. ?>
  50.  
  51. <br /><br /><br /><form method='post' action='modules/reg.inc.php'>Username: <input type='text' name='username' /><br />
  52. Password: <input type='password' name='password' /><br />
  53. Confirm Password: <input type='password' name='confirm' /><br />
  54. <input type='submit' value='Register!' />
  55. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement