Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.06 KB | None | 0 0
  1.  <?php // Connects to your Database
  2.  mysql_connect("localhost", "root", "root") or die(mysql_error());
  3.  mysql_select_db("users") or die(mysql_error());
  4.  //This code runs if the form has been submitted
  5.  if (isset($_POST['submit'])) {
  6.  
  7.  //This makes sure they did not leave any fields blank
  8.  if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
  9.         die('You did not complete all of the required fields');
  10.     }
  11.  
  12.  // checks if the username is in use
  13.     if (!get_magic_quotes_gpc()) {
  14.         $_POST['username'] = addslashes($_POST['username']);
  15.     }
  16.  $usercheck = $_POST['username'];
  17.  $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
  18.  or die(mysql_error());
  19.  $check2 = mysql_num_rows($check);
  20.  
  21.  //if the name exists it gives an error
  22.  if ($check2 != 0) {
  23.         die('Sorry, the username '.$_POST['username'].' is already in use.');
  24.                 }
  25.  //
  26. this makes sure both passwords entered match
  27.     if ($_POST['pass'] != $_POST['pass2']) {
  28.         die('Your passwords did not match. ');
  29.     }
  30.  
  31.     // here we encrypt the password and add slashes if needed
  32.     $_POST['pass'] = md5($_POST['pass']);
  33.     if (!get_magic_quotes_gpc()) {
  34.         $_POST['pass'] = addslashes($_POST['pass']);
  35.         $_POST['username'] = addslashes($_POST['username']);
  36.             }
  37.  
  38.  // now we insert it into the database
  39.     $insert = "INSERT INTO users (username, password)
  40.             VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
  41.     $add_member = mysql_query($insert);
  42.     ?>
  43.  
  44.  <h1>Registered</h1>
  45.  <p>Thank you, you have registered - you may now login</a>.</p>
  46. <?php }
  47.  else {  ?>
  48.  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  49.  <table border="0">
  50.  <tr><td>Username:</td><td>
  51.  <input type="text" name="username" maxlength="60">
  52.  </td></tr>
  53.  <tr><td>Password:</td><td>
  54.  <input type="password" name="pass" maxlength="10">
  55.  </td></tr>
  56.  <tr><td>Confirm Password:</td><td>
  57.  <input type="password" name="pass2" maxlength="10">
  58.  </td></tr>
  59.  <tr><th colspan=2><input type="submit" name="submit"
  60. value="Register"></th></tr> </table>
  61.  </form>
  62.  <?php
  63.  } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement