close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Check for duplicate email/username

Thread began 9/24/2009 9:27 am by georgina_barrett_187762 | Last modified 11/04/2010 2:45 pm by Jason Byrnes | 9247 views | 19 replies |

georgina_barrett_187762

Check for duplicate email/username

I am really struggling to get this to work. I want to validate the registration form to check if the username(email) is already in the database. I constructed the form via dataassist. I have read in earlier posts that say you can create a recordset that selects the username when it matches the form field username and then use COUNT to give a number. Then use the WA server validation to match that the COUNT is 0 to proceed.

The problem I think I am having is that the recordset it being produced when the page loads (so the username field is blank) and then when the form validates it on button press it validated against nothing.

However the validation is failing as it is going to my redirect on fail page - whether or not there is a duplicate email in the database.

The code for my recordset is;
$colname_username = "-1";
if (isset($_POST['Username'])) {
$colname_username = (get_magic_quotes_gpc()) ? $_POST['Username'] : addslashes($_POST['Username']);
}
mysql_select_db($database_mainconnect, $mainconnect);
$query_username = sprintf("SELECT COUNT(Customer.Username) FROM Customer WHERE Customer.Username=%s", GetSQLValueString($colname_username, "text"));
$username = mysql_query($query_username, $mainconnect) or die(mysql_error());
$row_username = mysql_fetch_assoc($username);
$totalRows_username = mysql_num_rows($username);?>

The code for the validation is;
<?php
if (isset($_POST["Register_x"])) {
$WAFV_Redirect = "Customer_LogIn.php?register=1";
$_SESSION['WAVT_CustomerRegistration_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateLE($row_username['COUNT(Customer.Username)'] . "",0 . "",true,4);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"CustomerRegistration");
}
}
?>

Sign in to reply to this post

Jason ByrnesWebAssist

To check whether a recordset has any rows using server validation, us Numeric Validation. Set the Server variable to "$totalRows_username" set the minimum to "-1" and the max to "0"

Sign in to reply to this post

georgina_barrett_187762

Thank you

I have done that and set the validation to 'when register button' pressed - however as soon as the page is loaded the validation error message appears and it doesn't matter whether I enter a duplicate email or not it fails every time.

This is my validation code;

<?php
if (isset($_POST["Register_x"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_CustomerRegistration_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateNM($totalRows_username . "",-1,0,"",",.",false,3);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"CustomerRegistration");
}
}
?>

This is the display error code;

<?php
if (ValidatedField('CustomerRegistration','CustomerRegistration')) {
if ((strpos((",".ValidatedField("CustomerRegistration","CustomerRegistration").","), "," . "3" . ",") !== false || "3" == "")) {
if (!(false)) {
?>
failed
<?php //WAFV_Conditional Customer_Registration.php CustomerRegistration(3:)
}
}
}?>

Sign in to reply to this post

Jason ByrnesWebAssist

add the following to your page after the </html> tag:

php:
<?php

if(isset($_SESSION['WAVT_CustomerRegistration_Errors'])) {
  unset(
$_SESSION['WAVT_CustomerRegistration_Errors']);
}
?>
Sign in to reply to this post

georgina_barrett_187762

Thank you that fixed the error displaying on page load. I figured out the other problems were due to the error validation code appearing before the recordset.

Sign in to reply to this post

thewebteam297175Beta Tester

Originally Said By: georgina_barrett_187762
  Thank you that fixed the error displaying on page load. I figured out the other problems were due to the error validation code appearing before the recordset.  



HALLELUJAH ! It's took me nearly 6 HOURS to fix this / find something here with a similar problem and I have used the Val' Toolkit wizards, read the tutorial 4 times.. reloaded from scratch 3 times and pulled my hair out twice !!!

Why the heck do I have to add a couple of lines of code by hand? - The rhetoric of your advertising - NO CODING NECESSARY - create pages in minutes .... YEAH !

I am fairly web experienced but couldn't spot this - gosh it's so frustrating!! - And I know I could have followed an online tutorial on the web and hand written / adapted the code from scratch in 6 hours just for a registration page. What a waste of time today has been.

At £20+ per hour that's an expensive lesson !!

Sign in to reply to this post

Andrew Read

Ditto!

It would seem that the code above is not being added to forms with validation applied to them automatically. Why is this not the case?

Why is this not documented?

I spent an entire morning searching for this solution to my problem! Again!

Sign in to reply to this post

Jason ByrnesWebAssist

it is not always the case that one would want the validation session cleared when the page is reloaded.

It is simply not posible for us to document every posible thing that can be accomplished with our tools. if there is something you are trying to accomplish and are not abel to, simply ask here and we will assist you.

Sign in to reply to this post

Andrew Read

Why would one not want this information to be dumped after the insert is completed?

You can not refresh the page and look at a blank form if you don't dump this data.

Sign in to reply to this post

Jason ByrnesWebAssist

The Session is only given a value when the form fails validation. if the form submits successfully, the session is reset to be empty.


The information is automatically dumped when the form successfully submits.

unsetting the session variable only comes into play if you want to clear the validated entries and the validation errors if the page is reloaded after it has failed validation.

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...