I have a syntax error that I can’t figure out what is wrong.
<?php
$fname = ucfirst (strtolower($_POST['fname']));
$lname = ucfirst (strtolower($_POST['lname']));
$lname = $_POST['lname'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$area = $_POST['area'];
$phone = $_POST['phone'];
if (empty($fname) || empty($lname) || empty($address) || empty($city) || empty($state) || empty($zip) || empty($area) || empty($phone)) {
echo "Please fill in all form fields. Click <a href='javascript: history.go(-1);return false '> here</a> to return to form.";
} else if (!is_numeric($zip) || !is_numeric($area) || !is_numeric($phone)) {
echo 'Please enter only numbers only for zip area code and phone number.<br /> Click <a href="javascript: history.go(-1);return false "> here</a>to return to the form.';
} else if (strlen($zip) != 5 || strlen($area) != 3 || (strlen($phone) != 7) {
echo "Please make sure zip code has 5 number, the area code has 3 number, and the phone number has 7 numbers.<br />Click <a href='javascript: history.go(-1);return false '> here</a>to return to the form.";
} else {
$contact = $lname . "," . $fname . "," . $address . "," . $city . "," . $state . "," . $zip . "," . $area . "," . $phone . "\n";
$contactfile = fopen("contacts.txt","a");
fwrite($contactfile,$contact);
fclose($contactfile);
echo "The following person was added: <br />";
echo $fname . "" . $lname . "<br />";
echo $city . "," . $state . "" . $zip . "<br />";
echo "(" . $area . ")" . $phone . "<br /><br />";
echo "Click <a href='javascript: history.go(-1);return false '> here</a>to return to the form.";
}
?>
The code that is showing the syntax error is:
} else if (strlen($zip) != 5 || strlen($area) != 3 || (strlen($phone) != 7) {
and
} else {
I don’t see what the problem is. Maybe someone might see what I’m not seeing.