PDA

View Full Version : Checking to see if email already exists in Database


John Langer
04-13-2010, 06:45 AM
I'm posting this here as it's VTK specific although I'm working from a CSS Forn Builder Form.

So I adapted the registration form a bit (just deleted a few fields). Then added an Insert Record behaviour.

Then tested and it all works great.

I then decided to add one more validation to the email field. The idea is to compare the email submitted with emails already stored in the Users database and say "That Email already exists" if there is a match.

Firstly the form shows that error ALL the time regardless of anything.

Secondly the form does not submit even if the emails do NOT match. (It doesn't submit if they do match but that's the expected behaviour). If I delete the validation (Like Entry) then it goes back to working properly.

I have temporarily bound the recordset email address to the page and they are displaying correctly.

I've attached my page if anyone could have a look. It must be something I'm doing wrong but I can't spot it.

Many thanks.

John Langer
04-13-2010, 08:14 AM
Mmm the attachment didn't attach. Here it is again.

Jason Byrnes
04-13-2010, 08:25 AM
the problem is that the recordset code is after the server validation code, the recordset code needs to be moved so it is before the server validation code.


also, the recordset is not being filtered, you should filter the email columnb on the email form element.

Instead of using like entry validation, use number validation. the idea is to check that the rcordset is empty.

for the server variable, use $totalRows_rsEmailMatch. In the number validation settings, set the minimum number to -1 and the max to 0

John Langer
04-13-2010, 08:53 AM
Hi Jason, many thanks for your help once again.

I think I've corrected it as you said although I wasn't too sure of what you meant by filtering the recordset email column on the email form element. However I had an educated guess. I'm now getting this error show up in the browser:
Fatal error: Call to undefined function getsqlvaluestring() in C:\wamp\www\CardiffMensConferences\my_area\users_R egistration.php on line 12

Line 12 is: $query_rsEmailMatch = sprintf("SELECT * FROM users WHERE UserEmail = %s", GetSQLValueString($colname_rsEmailMatch, "text"));

But I once again attach the whole page with the revised code if you wouldn't mind having another look.

Jason Byrnes
04-13-2010, 09:25 AM
1) The filter is set to use the server collection:
$_SERVER['Registration_group_Email_address']

It should be set to use the POST collection:
$_POST['Registration_group_Email_address']


2) The error is caused by code order still.

Move the following code:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>

to line 6 so it is before the recordset.

John Langer
04-13-2010, 09:48 AM
Many thanks Jason. That did the trick.

So much to learn...

Jason Byrnes
04-13-2010, 10:05 AM
no worries, glad to hear it's working.

info368164
07-01-2010, 02:56 AM
Hallo
ASP Server validation:

many times I have the necessity to compare two value, one in the textbox and another one in the db; if the values are the same the answer must be a error...
I haven't find of better who...
1) apply the command "Like Entry" whit a little modify:

if not recordset1.EOF or Not recordset1.BOF then
mailx=(recordset1.Fields.Item("mail").Value)
else
mailx="xyz@xyz.com" ' to bypass empty value
end if

WAFV_Errors = WAFV_Errors & WAValidateNOLE(cStr(Request.Form("email")) & "", mailx & "",true,2)



2) modify the code in WAVT_Scripts_VB.asp and add this function:

function WAValidateNOLE(value1,value2,required,number)
dim WAFV_ErrorMessage, isValid
WAFV_ErrorMessage = ""
isValid = true
if (value1 = value2 OR (required AND value1 = "")) then
isValid = false
end if
if (NOT isValid) then
WAFV_ErrorMessage = WAFV_ErrorMessage & "," & number
end if
WAValidateNOLE = WAFV_ErrorMessage
end function



Exist another method? If no, is possible to add this function (unLike Entry) at the next update?

Thank you
Regards
Luca

Jason Byrnes
07-01-2010, 06:55 AM
The two solutions you have proposed are the best way to handle this in ASP.

This will not be added to a future update however since we are no longer developing for ASP. We are focusing our developing efforts on PHP.