Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php // Connects to your Database
  2.  mysql_connect("localhost", "cameron_cameron", "kronos") or die(mysql_error());
  3.  mysql_select_db("cameron_login") 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.  // this makes sure both passwords entered match
  26.     if ($_POST['pass'] != $_POST['pass2']) {
  27.         die('Your passwords did not match. ');
  28.     }
  29.  
  30.     // here we encrypt the password and add slashes if needed
  31.     $_POST['pass'] = md5($_POST['pass']);
  32.     if (!get_magic_quotes_gpc()) {
  33.         $_POST['pass'] = addslashes($_POST['pass']);
  34.         $_POST['username'] = addslashes($_POST['username']);
  35.             }
  36.  
  37.  // now we insert it into the database
  38.     $insert = "INSERT INTO cameron_login  (cameron_cameron, kronos)
  39.             VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
  40.     $add_member = mysql_query($insert);
  41.     ?>
  42.  
  43.  <h1>Registered!</h1>
  44.  <p>Thank you, you have registered - you may now <a href="login.php">login</a>.</p>
  45.   <?php }
  46.  else {  ?>
  47.  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  48.  <table border="0">
  49.  <tr><td>Username:</td><td>
  50.  <input type="text" name="username" maxlength="60">
  51.  </td></tr>
  52.  <tr><td>Password:</td><td>
  53.  <input type="password" name="pass" maxlength="10">
  54.  </td></tr>
  55.  <tr><td>Confirm Password:</td><td>
  56.  <input type="password" name="pass2" maxlength="10">
  57.  </td></tr>
  58.  <tr><th colspan=2><input type="submit" name="submit"
  59. value="Register"></th></tr> </table>
  60.  </form>
  61.  <?php
  62.  } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement