Good Morning,
Sorry, I am rather new to php and I have been fighting with this problem for a while. I tried searching for the answer, but I wasn't really sure what to search for. I am trying to validate if the email address and user name are already taken and provide errors if they are. I can get it to recognize the user name and email are taken, but it will give the same error message for both (This email address is already registered.) I have posted the code:
// Making sure the email address is available.
$query = "SELECT user_name FROM customer_info WHERE (user_name='$un')";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_num_rows($result) == 0) { // Available.
$query = "SELECT email FROM customer_info WHERE (email='$e')";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_num_rows($result) == 0) { // Available.
// Create the activation code.
$a = md5(uniqid(rand(), true));
// Add the user.
$query = "INSERT INTO customer_info (user_name, password, first_name, last_name, address1, address2, city, state, zip, phone, mobile, fax, email, active, registration_date) VALUES ('$un', SHA('$p'), '$fn', '$ln', '$a1', '$a2', '$ci', '$st', '$zc', '$ph', '$mo', '$fx', '$e', '$a', NOW() )";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_affected_rows() == 1) { // If it ran OK.
// Send the email.
$body = "Thank you for registering with domain name at [url]www.domainname.com[/url]. To activate your account, please click on this link:\n\n";
$body .= "http://www.domainname.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
mail($_POST['email'], 'Registration Confirmation', $body, 'From: [email]blah@blah.com[/email]');
// Finish the page.
echo '<h3>Thank you for registering! A confirmation email has been sent to the email address you have provided. Please click on the link in that email in order to activate your account.</h3>';
include ('./includes/footer.html'); // Include the HTML footer.
exit();
} else { // If it did not run OK.
echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience. Please contact the site administrator at <a href="contact.html" title="Contact Help" target="_blank">blah@blah.com</a></font></p>';
}
} else { // The email address is not available.
echo '<p><font color="red" size="+1">That email address has already been registered. If you have forgotten your password, please click <a href="forgot_password.php" target="_self">here</a> to have have your password sent to you.</font></p>';
}
} else { // If one of the data tests failed.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}
mysql_close(); // Close the database connection.