After spending hours I still cant figure it out. I'm trying to validate an email address but every time and no matter what Ii type it gives me the message as if it was empty "You did not enter an email address!".
Edit: Fixed invalid email address error because I did not add a name to my input text. Now when I enter a correct email, it keeps loading "please wait". Any ideas? Is it because its not connecting to mysql?
$email = mysql_real_escape_string($_POST['signup-email']);
if(empty($email)){
$status = "error";
$message = "You did not enter an email address!";
}
else if(!preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA- Z0-9_]+)*\.[a-zA-Z]{2,4}$/', $email)){ //validate email address - check if is a valid email address
$status = "error";
$message = "You have entered an invalid email address!";
}
else {
$existingSignup = mysql_query("SELECT * FROM signups WHERE signup_email_address='$email'");
if(mysql_num_rows($existingSignup) < 1){
$date = date('Y-m-d');
$time = date('H:i:s');
$insertSignup = mysql_query("INSERT INTO signups (signup_email_address, signup_date, signup_time) VALUES ('$email','$date','$time')");
if($insertSignup){ //if insert is successful
$status = "success";
$message = "You have been signed up!";
}
else { //if insert fails
$status = "error";
$message = "Ooops, Theres been a technical error!";
}
}
else { //if already signed up
$status = "error";
$message = "This email address has already been registered!";
}
}
HTML:
<div id="signupform">
<form id="newsletter-signup" action="?action=signup" method="post">
<fieldset>
<input type="text" name="signup-email" id="signup-email" size="20" value="Email Address" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<input type="submit" id="signup-button" value="+"/>
</br></br><p id="signup-response"></p>
</fieldset>
</form>