Check for duplicate email address as well as username (user registration)
Hi all,
This thread might be totally pontless if the extension actually performs this functionality, but I couldnt find a menu to let me check that the registrants email address doesnt already exist as well as username. Is it possible?
Checking for a duplicate email address in the database is fairly essential functionality for me. I never want the same email address registering different accounts.
I modified the code which checks the database for a duplicate username so that it also checks for a duplicate email. It may be of interest to others.
You will need to replace 'u_email' and 'u_username' with your own email/username field name's.
You could easily modify it to check that the person registering doesnt have the same pet, car, street address etc as anyone else already registered too (if you wanted), as well as multiple other checks.
---------------------------------
<?php
// *** Redirect if username or email exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
//check username
$MM_dupKeyRedirect="register.php?userExists=true";
$loginUsername = $_POST['u_username'];
$LoginRS__query = "SELECT u_username FROM users WHERE u_username='" . $loginUsername . "'";
mysql_select_db($database_watestConn, $watestConn);
$LoginRS=mysql_query($LoginRS__query, $watestConn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//check email
$MM_dupKeyRedirect_email="register.php?emailExists=true";
$loginEmail = $_POST['u_email'];
$LoginRS__query_email = "SELECT u_email FROM users WHERE u_email='" . $loginEmail . "'";
mysql_select_db($database_watestConn, $watestConn);
$LoginRS_email=mysql_query($LoginRS__query_email, $watestConn) or die(mysql_error());
$loginFoundEmail = mysql_num_rows($LoginRS_email);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}else if($loginFoundEmail){ //if there is a row in the database, the email was found
$MM_qsChar = "?";
//append the email to the redirect page
if (substr_count($MM_dupKeyRedirect_email,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect_email = $MM_dupKeyRedirect_email . $MM_qsChar ."reqemail=".$loginEmail;
header ("Location: $MM_dupKeyRedirect_email");
exit;
}
}
?>
---------------------------------