unique email validation: calling SQL from JS?
Posted: Wed Jan 19, 2011 12:25 pm
Hi:
I have a registereduser table with unique "username" and "email". How can I validate that "uniqueness" in a Javascript call?
I have an email field in "registeredusers" and an email field in the form. Then on "Submit" call the following JS:
However, this is not working. How can I make it work?
Your help is appreciated.
Thanks
Thomas
I have a registereduser table with unique "username" and "email". How can I validate that "uniqueness" in a Javascript call?
I have an email field in "registeredusers" and an email field in the form. Then on "Submit" call the following JS:
Code: Select all
<?php
$email_taken = 0;
$email = trim(get_param('email'));
if (!empty($email))
{
$strSQL = "select email from registeredusers where email = ".$email;
$db->query($strSQL);
if($db->next_record())
{
$email_taken = 1;
}
}
?>
if(<?php echo $email_taken;?>")
{
alert("This email address is already taken. Please choose a different email");
document.getElementById("email").focus();
return false;
}
Your help is appreciated.
Thanks
Thomas