Hello All,
In a series of if / ifelse statements, I am checking the validation of form items. Of those items, I am most concerned with e-mail. If the e-mail field is submitted blank, I display an error message and revert back to the form.
BUT, if the e-mail field contains something, I want to check it.
Every e-mail address I submit is now being considered "invalid". I think this has something to do with my $msg variable, so can you guys take a look at my logic?
I strongly believe that this problem lies within the $msg variable, but it's just a guess for now. Any and all help is appreciated!
<?php
// A series of if / if else statements appears here until we reach the email validation...
// If e-mail is not empty, check for a valid format
elseif ($email)
{
$email = trim($email);
#PATTERNS FOR NAME, DOMAIN, AND TOP-LEVEL DOMAINS
$name = "/[-!#$%&\'*+\.\/0-9=?A-Z`{|}~]+";
$host = "([-0-9A-Z]+\,)+";
$tlds = "([0-9A-Z]){2,4}$/i";
#CHECK THE VALIDITY OF THE EMAIL FORMAT
if( !preg_match($name."@".$host .$_tlds,$email) )
{
$msg = "<font face='Arial' size='+1' color='red'>Your sign up has failed!</font><br>
<font face='Arial' color='#4D50A3' size='+1'>Your e-mail address is formatted incorectly!<br><br>
Click <a href='admin_sign_up.php'>here</a> to sign up again.";
}
}
else
{
// CONNECT TO SQL
// CONNECT TO THE DATABASE
// ENTER THE FORM INFORMATION INTO SQL
// GIVE A RESULT
// IF RESULT, DISPLAY THE FOLLOWING MESSAGE
if ($result) { $msg = ("<br><br><h2><font face='Arial' color='#4d50a3'>New profile for <font color = 'black'>$firstname $lastname</font> added!</font></h2><br><font face='Arial'><br>
<b>Click <a href='default.htm'>HERE</a> to log-out.</b><br><br><b>Click <a href='admin_add.php'>HERE</a> to add another employee!</b><br><br><b>Click <a href='admin_edit_home.htm'>HERE</a> to return to administration home.</b></font>"); }
}
?>
I then echo $msg in the main body of my document.
My theory is that it's accepting the $msg variable from the e-mail validation, and skipping the else statement all together. It's printing the e-mail validation error to my screen. Is there a way around this?