Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //If submitted has been posted, create an errors array
- //If there has been nothing posted in the email field, add an error
- //to the array. If an email has been posted, trim any excess characters
- //If there has been something posted to both password fields,
- //check to see if they match. If they don't match, add an error to the array.
- //If they do match, trim excess characters. If the password field is empty,
- //add an error to the array.
- if (isset($_POST['submitted'])){
- require_once ("mysql_connect.php");
- $errors=array();
- //checking for preregistered accounts
- //mysql query
- $q_check = "SELECT * FROM users WHERE user='$user' or email='$email'";
- //runs query
- $usercherck = @mysqli_query($dbc, $q_check) or die(mysql_error());
- //mysql query to check for same values
- $row_usercheck = mysql_fetch_assoc($usercheck);
- //number of rows that have matching values
- $totalRows_usercheck = mysql_num_rows($usercheck);
- if ( $totalRows_usercheck > 0) {
- $errors[] = 'Someone has already registered with that information!';
- echo "$errors";
- }
- if (empty($_POST['email'])){
- $errors[] = 'Please enter an email address.';
- } else {
- $email = trim($_POST['email']);
- }
- if (!empty($_POST['pass1'])){
- if ($_POST['pass1'] != $_POST['pass2']) {
- $errors[] = 'Your passwords do not match.';
- } else {
- $pass = trim ($_POST['pass1']);
- }
- } else {
- $errors[] = 'Please enter a password.';
- }
- if (empty($errors)) {
- require_once ("mysql_connect.php");
- //Makes mysql query
- $q = "INSERT INTO users (email, pass, registration_date) VALUES ('$email', SHA1('$pass1'), NOW())";
- //Runs query
- $r = @mysqli_query ($dbc, $q);
- //If query ran successfully
- if ($r) {
- echo '<h1>Registration successful!</h1>';
- } else {
- echo '<h1>Error: registration not successful.</h1>';
- }
- mysqli_close($dbc);
- exit();
- } else {
- foreach ($errors as $msg) {
- echo "$msg<br />\n";
- }
- }
- ?>
- <h1>Register</h1>
- <form action="register.php" method="post">
- <p>Email: <input type="text" name="email" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"/></p>
- <p>Password: <input type="password" name="pass1" maxlength="40" value="<?php if (isset($_POST['pass1'])) echo $_POST['pass1']; ?>"/></p>
- <p>Re-enter password: <input type="password" name="pass2" maxlength="40" value="<?php if (isset($_POST['pass2'])) echo $_POST['pass2'];?>"/></p>
- <p><input type="submit" name="submit" value="register" /></p>
- <input type="hidden" name="submitted" value="TRUE" />
- </form>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement