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