close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Check for duplicate email address as well as username (user registration)

Thread began 10/02/2009 1:01 pm by phil | Last modified 1/16/2010 8:30 am by dan361748 | 14676 views | 23 replies |

phil

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;
}
}
?>

---------------------------------

Sign in to reply to this post

tom92909Beta Tester

Yes, I'm actively working on something similar. I need to offer a signup using an email address, but the same is true, I need to verify if the email address already exists in the database.

Is there a tutorial, recipe, or sample for such?

Would a Server Side validation be best for this? If so is there an example of how to implement this?

I would agree that this is an essential functionality for anyone that gathers/collects email addresses.

Sign in to reply to this post

Jason ByrnesWebAssist

First you need to create a recordset to see if the email or username existst in the database.

If you want to be able to display a different message if the user name is already in the database, you need to create two recordset. One to check for the user name, one to check for the password.

crate the first recordset, named usernameLookup. Set it to filter the username column on the username form element.

Create the second recordset as emailLookup, Set it to filter the email column on the email form element.

Then add server validation. For the username, use Numeric validation. Set the server variable to "$totalRows_usernameLookup", set the minimum to -1 and the max to 0. same for the the email, use numeric validation. Set the server variable to "$totalRows_emailLookup" the minimum should be set to -1 and the max set to 0.

Setting the validation this way will check that either recordset is empty.

Sign in to reply to this post

PaulBeta Tester

Hi,

Gave this same issue some thought some time ago and decided for simplicity and effectiveness, to use the email address as the username during registration.

This way, you've got a unique username, which is validated, and you have an email for forgotten passwords etc.

You may, if not already done so, wish to consider this option.

Paul.

Sign in to reply to this post

phil

I thought of that and it would work nicely in many situations (such as e-commerce). However if your site has a social-networking aspect then users will want unique display names when making posts etc, so a workaround will always be needed.

It would be good to get unique checks on username AND email within the WA extensions, though it is fairly easy to create your own workaround as above.

Sign in to reply to this post

dlovas275157

I set up a similar server validation to check that both username and email are unique upon registration. Vaildation works, only one problem.

When the validation catches a duplicate entry on either the username or email field, the form reloads with the validation prompt, but the form is cleared out and the user has to re-type all the info in again in order to try to register again. Makes the registration process difficult for users.

Any way to preserve the form data? Anyone else have this issue too?

Sign in to reply to this post

Jason ByrnesWebAssist

When validation fails, the fields that pass validation are stored in the Validated Entries binding group.


Bind the initial Values of the form elements to the corresponding element in the Validated Entries binding group.

Sign in to reply to this post

dlovas275157

That worked. Thanks.

Sign in to reply to this post

bryan107833

Validation working but then always gets error

I have added the 2 record sets etc. and it seemed to be working except that it always now defaults to the "Email exists page" even when it does not. I do have the validation above the Insert Record Behavior. Any ideas? Thanks.

Attached Files
dealer_insert_082009.zip
Sign in to reply to this post

Jason ByrnesWebAssist

line 84:

php:
$WAFV_Errors .= WAValidateNM(totalRows_emailLookup . "",-1,0,"",",.",true,2);





needs to be changed to:

php:
$WAFV_Errors .= WAValidateNM($totalRows_emailLookup . "",-1,0,"",",.",true,2);
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...