In a series of if / elseif statement, I am checking the status of several fields. If they are empty, control sends an error message, and echos it in the main body.
If all those fields are filled with data, they pass the (not empty) test, and jump to the else statement. Within the else statement, I have a series of nested if's...
If the e-mail passes the format test, check the phone number. If phone number passes the format test, check the fax. If the fax passes the test (All fields have passed at this point), connect to the database and enter information.
If one of those three formatting tests fail, control should jump to the corresponding else statement, produce an error message, and echo it in the main body. In compiling this code, I get an "unexpected {" error message. I can not see it...If anyone can offer any suggestions, I'd be very thankful. - Mike
if (empty($title))
{
$msg = "<font face='Arial' size='+1' color='red'>Employee submission has failed!</font><br>
<font face='Arial' color='#4D50A3' size='+1'>Enter an employee's title!<br><br>
Click <a href='add_profile.htm'>here</a> to register this employee again.";
}
// Error check the phone number field - Required field
elseif (empty($phone))
{
$msg = "<font face='Arial' size='+1' color='red'>Employee submission has failed!</font><br>
<font face='Arial' color='#4D50A3' size='+1'>Enter an employee / department phone number!<br><br>
Click <a href='add_profile.htm'>here</a> to register this employee again.";
}
else // The form has been completed
{
// The form is valid and all fields contain data
// But first, check the format of the e-mail, phone number, and fax
if ($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 phone number field
if ($phone)
{
$phone = trim($phone);
// Patterns for number
$_first = "([0-9])";
$_last = "([0-9])";
}
// Check the validity of the fax field
if ($fax)
{
$fax = trim($fax);
// Patterns for number
$_first_three = "([0-9])";
$_last_four = "([0-9])";
// All fields pass error checking, so submit information to SQL
// Connect to SQL
// Connect to the database within SQL
// Enter the information into the database
// Give a result
// If there is a result, display the following information
}
elseif
{
// Apply the validity check on the fax field
if( !preg_match($_first_three."-".$_last_three)
{
$msg = "<font face='Arial' size='+1' color='red'>Your sign up has failed!</font><br>
<font face='Arial' color='#4D50A3' size='+1'>Your fax information is formatted incorrectly!<br>Enter your fax number in the form of ###-#### <br><br>
Click your browser 'Back' button<br><br>
or<br><br>
Click <a href='add_profile.htm'>HERE</a> to re-complete your registration.";
}
}
elseif
{
// Apply the validity check on the phone number field
if( !preg_match($_first."-".$_last)
{
$msg = "<font face='Arial' size='+1' color='red'>Your sign up has failed!</font><br>
<font face='Arial' color='#4D50A3' size='+1'>Your phone number information is formatted incorrectly!<br>Enter your phone number in the form of ###-#### <br><br>
Click your browser 'Back' button<br><br>
or<br><br>
Click <a href='add_profile.htm'>HERE</a> to re-complete your registration.";
}
}
else
{
// Check the validity of the e-mail 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 incorrectly!<br><br>
Click your browser 'Back' button<br><br>
or<br><br>
Click <a href='add_profile.htm'>HERE</a> to re-complete your registration.";
}
}
}