Wow, this was some great stuff. I was looking at a general concept for validating an email address.
I have a customer table that when they create an account, I don't want repeat entries. In other words,
if the enter their email address and it already exists, I want it to return with, there is an account with this email address already............go to forget your user name/ password.
Should I use if ($_POST[emai]) array to check? Should I do a select statement to the mySQL database, and if returns with a row, so it is true, give the error message?
Any code or advice would be great.
Here is the function I created to check the database for a dupe email address:
// if returns true success, false means there were dupe emails.
function checkEmailDupes($email) {
global $connection;
$UCemail = strtoupper($email);
$query = "SELECT email FROM customer
WHERE upper(email) =
'{$UCemail}'";
$checkEmail = mysql_query($query, $connection);
confirm_query($checkEmail);
$numRows = mysql_num_rows($checkEmail);
if($numRows==0){
return true;
} else {
return false;
}
then i use the function:
$EmNoDup =false;
if(checkEmailDupes($email)){
$EmNoDup =true;
}else {
//header("Location:cform.php");
//exit;
echo "<script>alert('dupe email')</script>";
if(empty($errors) && $EmNoDup == true ) {
$query = "INSERT INTO customer (............................and so on.
Does this look like a generally accepted code? I am quite new.............thanks KP
Looks good enough to me.
Concerning clientside validation I would propose to call the validation function when submitting the form not when clicking the submitbutton, cause you can also submit a form by just typing <enter> when the focus is on a form field.
So this seems more proper to me
<form method="post" name="msgform" onsubmit="return checkForm();">
<input type="submit">
</form>
than this
<form method="post" name="msgform">
<input type="submit" onclick="return checkForm();">
I really found this useful except the links to the files no longer work. I would really like to see the files. Can anyone help me here as I am a newbie to php?