Hello all. I've been trying to figure out what I've done wrong in this code and I think I've looked at it too long to see what's not working right. Please help. Thanks to any who are willing to help out.
Here it is:
<?php
$message = '<font color="red">The following errors occurred:<br><br>';
$problem = FALSE;
# Check for required firstName
if (strlen($_POST['firstName']) > 0){
if (!eregi("^[[:alpha:]-']{2,}$"), stripslashes(trim($_POST['firstName']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid First Name.</li></ul>';
}
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your First Name.</li></ul>';
}
# Check for required lastName
if (strlen($_POST['lastName']) > 0){
if (!eregi("^[[:alpha:]-']{2,}$"), stripslashes(trim($_POST['lastName']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Last Name.</li></ul>';
}
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your Last Name.</li></ul>';
}
# Check for street
if (strlen($_POST['street']) > 0){
if (!eregi("^[[:alnum:][:blank:]-.']{4,}$"), stripslashes(trim($_POST['street']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Street Address.</li></ul>';
}
}
# Check for city
if (strlen($_POST['city']) > 0){
if (!eregi("^[[:alpha:][:blank:]-.']{2,}$"), stripslashes(trim($_POST['city']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid City.</li></ul>';
}
}
# Check for state
if (strlen($_POST['state']) > 0){
if (!eregi("[AL][AK][AS][AZ][AR][CA][CO][CT][DE][DC][FM][FL][GA][GU][HI][ID][IL][IN][IA][KS][KY][LA][MA][MD][ME][MH][MI][MN][MO][MS][MT][NE][NH][NV][NJ][NM][NY][NC][ND][MP][OH][OK][OR][PW][PA][PR][RI][SC][SD][TN][TX][UT][VT][VI][VA][WA][WV][WI][WY]"), stripslashes(trim($_POST['state']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid State.</li></ul>';
}
}
# Check for zip
if (strlen($_POST['zip']) > 0){
if (!eregi("^([0-9]{5})(-[0-9]{4})?$"), stripslashes(trim($_POST['zip']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Zip.</li></ul>';
}
}
# Check for phone
if (strlen($_POST['phone']) > 0){
if (!eregi("^([0-9]{3})(-[0-9]{3})(-[0-9]{4}$"), stripslashes(trim($_POST['phone']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Phone Number.</li></ul>';
}
}
# Check for required e-mail
if (strlen($_POST['email']) > 0){
if (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$"), stripslashes(trim($_POST['email']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid E-mail Address.</li></ul>';
} else {
$email = eregi_replace("^[[:alnum:][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", '<a href="mailto:'$email'">E-mail</a>', stripslashes(trim($_POST['email'])))){
}
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your E-mail Address.</li></ul>';
}
# Check for required comments
if (strlen($_POST['comments']) > 0){
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your Comments.</li></ul>';
}
if ($_POST['noCom'] > NULL) {
$com = "Checked";
} else $com = "Not Checked";
if (!$problem){
echo "<center><strong>Please check your information.</strong></center><br><br>";
echo '<form action="http://www.arrowcontracting.com/mail.php">';
echo "First Name: <b>($_POST['firstName'])</b><br>";
echo "<input type=\"hidden\" name=\"firstName\" value=\"$_POST['firstName']\">";
echo "Last Name: <b>($_POST['lastName'])</b><br><br>";
echo "<input type=\"hidden\" name=\"lastName\" value=\"$_POST['lastName']\">";
if (strlen($street) > 0){
echo "Street: <b>$street</b><br>";
echo "<input type=\"hidden\" name=\"street\" value=\"$_POST['street']\">";
}
if (strlen($city]) > 0){
echo "City: <b>$city</b> ";
echo "<input type=\"hidden\" name=\"city\" value=\"$_POST['city']\">";
}
if (strlen($state) > 0){
echo "State: <b>$state</b> ";
echo "<input type=\"hidden\" name=\"state\" value=\"$_POST['state']\">";
}
if (strlen($zip) > 0){
echo "Zip: <b>$zip</b>";
echo "<input type=\"hidden\" name=\"zip\" value=\"$_POST['zip']\">";
}
echo "<br><br>";
if (strlen($phone) > 0){
echo "Phone: <b>$phone</b><br><br>";
echo "<input type=\"hidden\" name=\"phone\" value=\"$_POST['phone']\">";
}
echo "E-mail: <b>($_POST['email'])</b><br>";
echo "<input type=\"hidden\" name=\"email\" value=\"$_POST['email']\">";
echo '"I do not wish to receive communications from ArrowContracting.com": $com';
echo "<input type=\"hidden\" name=\"com\" value=\"$_POST['com']\">";
echo '<br><br><input type="button" value=" Back " onClick="history.back()"> <input type="submit" value=" Submit "></form>';
} else {
echo $message;
echo '</font><br><br><strong>Please go back and try again</strong><br><br><br>';
echo '<form><input type="button" value=" Back " onClick="history.back()"></form>';
}
?>
I hope you guys can help me out.