Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.04 KB | None | 0 0
  1. <?php
  2. // Connects to your Database
  3. mysql_connect("mysql4.000webhost.com", "username", "password") or die(mysql_error()); mysql_select_db("a5317515_blogger") or die(mysql_error());
  4. //This code runs if the form has been submitted
  5. if (isset($_POST['submit'])) {
  6. //This makes sure they did not leave any fields blank
  7. if (!$_POST['username'] |
  8. !$_POST['pass'] |
  9. !$_POST['pass2'] )
  10. {  
  11.     die('You did not complete all of the required fields');
  12.     }
  13.     // checks if the username is in use    
  14.     if (!get_magic_quotes_gpc()) {     
  15.     $_POST['username'] = addslashes(
  16.     $_POST['username']);
  17.         }
  18.         $usercheck = $_POST['username'];
  19.         $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error());
  20.         $check2 = mysql_num_rows($check);
  21.         //if the name exists it gives an error
  22.         if ($check2 != 0)
  23.         {      
  24.         die('Sorry, the username '.$_POST['username'].' is already in use.');
  25.         }
  26.          // this makes sure both passwords entered match    
  27.          if ($_POST['pass'] != $_POST['pass2'])
  28.          {     
  29.          die('Your passwords did not match. ');
  30.             }  
  31.             // here we encrypt the password and add slashes
  32.             if needed  
  33.             $_POST['pass'] = md5($_POST['pass']);  
  34.             if (!get_magic_quotes_gpc())
  35.             {
  36.                 $_POST['pass'] = addslashes($_POST['pass']);
  37.                 $_POST['username'] = addslashes($_POST['username']);
  38.                  }
  39.                   // now we insert it into the database    
  40.                   $insert = "INSERT INTO users (username, password)            
  41.                   VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
  42.                   $add_member = mysql_query($insert);
  43.                     ?>
  44.                     <h1>Register</h1>
  45.                     <p>Please fill out the forms below</a>.</p>
  46. <?php
  47.     }
  48.         else
  49.          {   ?>
  50.          <form action="<?php echo $_SERVER['PHP_SELF'];?>"method="post">
  51.          <table border="0">
  52.          <tr>  
  53.          <td width="120">
  54.          Username:
  55.          </td>
  56.          <td width="356">
  57.          <input type="text" name="username" maxlength="60">
  58.          </td></tr>
  59.          <tr><td>
  60.          Password:
  61.          </td><td>
  62.          <input type="password" name="pass" maxlength="10">
  63.          </td></tr>
  64.          <tr><td>
  65.          Confirm Password:
  66.          </td>
  67.          <td>
  68.          <input type="password" name="pass2" maxlength="10">
  69.          </td></tr>
  70.          <tr><td>
  71.          Email:
  72.          </td><td>
  73.          <input type="text" name="email" maxlength="50">
  74.          </td></tr>
  75.          <tr><td>
  76.          Confirm Email:
  77.          </td><td>
  78.          <input type="text" name="email2" maxlength="50" />
  79.          </td></tr>
  80.          <p> Tell us a little bit about yourself </p>
  81.          <tr><td>
  82.          First Name:
  83.          </td><td>
  84.          <input type="text" name="name" maxlength="20">
  85.          </td></tr>
  86.          <tr><td>
  87.           Surname:
  88.          </td><td>
  89.          <input type="text" name="name2" maxlength="20">
  90.          </td></tr>
  91.                 <tr>
  92.          <th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form>
  93.          <?php
  94.          }
  95.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement