Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.53 KB | None | 0 0
  1. <?php
  2. //If submitted has been posted, create an errors array
  3. //If there has been nothing posted in the email field, add an error
  4. //to the array. If an email has been posted, trim any excess characters
  5. //If there has been something posted to both password fields,
  6. //check to see if they match. If they don't match, add an error to the array.
  7. //If they do match, trim excess characters. If the password field is empty,
  8. //add an error to the array.
  9. if (isset($_POST['submitted'])){
  10.     require_once ("mysql_connect.php");
  11.     $errors=array();
  12.     //checking for preregistered accounts
  13.     //mysql query
  14.     $q_check = "SELECT * FROM users WHERE user='$user' or email='$email'";
  15.     //runs query
  16.     $usercherck = @mysqli_query($dbc, $q_check) or die(mysql_error());
  17.     //mysql query to check for same values
  18.     $row_usercheck = mysql_fetch_assoc($usercheck);
  19.     //number of rows that have matching values
  20.     $totalRows_usercheck = mysql_num_rows($usercheck);
  21.     if ( $totalRows_usercheck > 0) {
  22.         $errors[] = 'Someone has already registered with that information!';
  23.         echo "$errors";
  24.        
  25.         }
  26.     if (empty($_POST['email'])){
  27.         $errors[] = 'Please enter an email address.';
  28.     } else {
  29.         $email = trim($_POST['email']);
  30.     }
  31.     if (!empty($_POST['pass1'])){
  32.         if ($_POST['pass1'] != $_POST['pass2']) {
  33.             $errors[] = 'Your passwords do not match.';
  34.         } else {
  35.             $pass = trim ($_POST['pass1']);
  36.         }      
  37.     } else {
  38.         $errors[] = 'Please enter a password.';
  39.     }
  40.     if (empty($errors)) {
  41.         require_once ("mysql_connect.php");
  42.         //Makes mysql query
  43.         $q = "INSERT INTO users (email, pass, registration_date) VALUES ('$email', SHA1('$pass1'), NOW())";
  44.         //Runs query
  45.         $r = @mysqli_query ($dbc, $q);
  46.         //If query ran successfully
  47.         if ($r) {
  48.             echo '<h1>Registration successful!</h1>';
  49.         } else {
  50.             echo '<h1>Error: registration not successful.</h1>';
  51.         }
  52.         mysqli_close($dbc);
  53.         exit();
  54.         } else {
  55.             foreach ($errors as $msg) {
  56.                 echo "$msg<br />\n";
  57.         }  
  58.     }
  59.    
  60. ?>
  61.  
  62. <h1>Register</h1>
  63. <form action="register.php" method="post">
  64.     <p>Email: <input type="text" name="email" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"/></p>
  65.     <p>Password: <input type="password" name="pass1" maxlength="40" value="<?php if (isset($_POST['pass1'])) echo $_POST['pass1']; ?>"/></p>
  66.     <p>Re-enter password: <input type="password" name="pass2" maxlength="40" value="<?php if (isset($_POST['pass2'])) echo $_POST['pass2'];?>"/></p>
  67.     <p><input type="submit" name="submit" value="register" /></p>
  68.     <input type="hidden" name="submitted" value="TRUE" />
  69. </form>
  70. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement