Jump to content
Larry Ullman's Book Forums

Password & Active Fields Not Populating


Recommended Posts

Hello:

 

I've modified the register.php script for my needs. As I tested my script, the fields in the users table (pass and active) are not being populated. Yet, all the other fields are populating with no issue.

 

Can someone look at my register.php and see what may be causing the issue?

 

Thank you in advance.

 

<?php
// This is the registration page for the site.
// Require the configuration before any PHP code as the configuration controls error reporting:
require ('config.inc.php');
// The config file also starts the session.
// Include the header file:
include ('header.html');
// Require the database connection:
require (MYSQL);
// For storing registration errors:
$reg_errors = array();
// Check for a form submission:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Check for a first name:
if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $_POST['first_name'])) {
 $fn = mysqli_real_escape_string ($dbc, $_POST['first_name']);
} else {
 $reg_errors['first_name'] = 'Please enter your first name!';
}

// Check for a last name:
if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $_POST['last_name'])) {
 $ln = mysqli_real_escape_string ($dbc, $_POST['last_name']);
} else {
 $reg_errors['last_name'] = 'Please enter your last name!';
}

// Check for a username:
if (preg_match ('/^[A-Z0-9]{2,30}$/i', $_POST['username'])) {
 $u = mysqli_real_escape_string ($dbc, $_POST['username']);
} else {
 $reg_errors['username'] = 'Please enter a desired name!';
}

// Check for an email address:
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
 $e = mysqli_real_escape_string ($dbc, $_POST['email']);
} else {
 $reg_errors['email'] = 'Please enter a valid email address!';
}
// Check for a password and match against the confirmed password:
if (preg_match ('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){6,20}$/', $_POST['pass1']) ) {
 if ($_POST['pass1'] == $_POST['pass2']) {
  $p = mysqli_real_escape_string ($dbc, $_POST['pass1']);
 } else {
  $reg_errors['pass2'] = 'Your password did not match the confirmed password!';
 }
} else {
 $reg_errors['pass1'] = 'Please enter a valid password!';
}

if (empty($reg_errors)) { // If everything's OK...
 // Make sure the email address and username are available:
 $q = "SELECT email, username FROM users WHERE email='$e' OR username='$u'";
 $r = mysqli_query ($dbc, $q);

 // Get the number of rows returned:
 $rows = mysqli_num_rows($r);

 if ($rows == 0) { // No problems!

  // Create the activation code:
  $a = md5(uniqid(rand(), true));

  // Add the user to the database...

  $q = "INSERT INTO users (first_name, last_name, username, email, pass, active, registration_date)
	 VALUES ('$fn', '$ln', '$u', '$e', '"  .  get_password_hash($p) .  "', '$a', NOW() )";

  $r = mysqli_query ($dbc, $q);
  if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

   // Get the user ID:
   // Store the new user ID in the session:
   $uid = mysqli_insert_id($dbc);
//    $_SESSION['reg_user_id']  = $uid; 

   // Display a thanks message:
   //echo '<h3>Thanks!</h3><p>Thank you for registering! You may now log in and access the site\'s content.</p>';

   // Send the email:
   $body = "Thank you for registering at www.helenbradshawphotography.com. To activate your account, please click on this link:\n\n";
   $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a";
   mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@helenbradshawphotography.com');

   // Finish the page:
   echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>';
   include ('footer.html'); // Include the HTML footer.
   exit(); // Stop the page.

  } else { // If it did not run OK.
   trigger_error('You could not be registered due to a system error. We apologize for any inconvenience.');
  }

 } else { // The email address or username is not available.

  if ($rows == 2) { // Both are taken.

   $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.';  
   $reg_errors['username'] = 'This username has already been registered. Please try another.';  
  } else { // One or both may be taken.
   // Get row:
   $row = mysqli_fetch_array($r, MYSQLI_NUM);

   if( ($row[0] == $_POST['email']) && ($row[1] == $_POST['username'])) { // Both match.
 $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.';
 $reg_errors['username'] = 'This username has already been registered with this email address. If you have forgotten your password, use the link at right to have your password sent to you.';
   } elseif ($row[0] == $_POST['email']) { // Email match.
 $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.';	 
   } elseif ($row[1] == $_POST['username']) { // Username match.
 $reg_errors['username'] = 'This username has already been registered. Please try another.';  
   }

  } // End of $rows == 2 ELSE.

 } // End of $rows == 0 IF.

} // End of empty($reg_errors) IF.
} // End of the main form submission conditional.
// Need the form functions script, which defines create_form_input():
require ('form_functions.inc.php');
?>
<div id="stylized1" class="myform1">
<form action="register.php" method="post" accept-charset="utf-8">
 <label><strong>First Name:</strong></label><?php create_form_input('first_name', 'text', $reg_errors); ?>
   <br><br><br>
 <label><strong>Last Name:</strong></label><?php create_form_input('last_name', 'text', $reg_errors); ?>
   <br><br><br>
 <label><strong>Username:</strong></label><?php create_form_input('username', 'text', $reg_errors); ?>
   <br><br><br>
 <label><strong>Email Address:</strong></label><?php create_form_input('email', 'text', $reg_errors); ?>
   <br><br><br>
 <label><strong>Password:</strong></label><?php create_form_input('pass1', 'password', $reg_errors); ?><br><br>
 <small>Must be between 6 and 20 characters long, with at least one lowercase letter, one uppercase letter, and one number</small>

   <br><br><br>
 <label><strong>Confirm Password:</strong></label><?php create_form_input('pass2', 'password', $reg_errors); ?>
	  <br><br><br>
 <label>    </label><img src="Captcha/captcha/captchac_code.php" id="captcha"><br><br>
    <label>  </label><input type="text" name="imgverify" value="" maxlength="100" size="10" /> <br><br>
    <button type="submit">Submit</button>

</form>
</div>
<?php // Include the HTML footer:
include ('footer.html');
?>

Link to comment
Share on other sites

 Share

×
×
  • Create New...