Having trouble figuring the syntax error problem.

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.

you had an extra (
[php]} else if (strlen($zip) != 5 || strlen($area) != 3 || (strlen($phone) != 7) { [/php]
[php]} else if (strlen($zip) != 5 || strlen($area) != 3 || strlen($phone) != 7) {[/php]

Thanks, Noodles. I got everything working again. I finally finished my last php script.

No problem happy you solved your problems.
Just click the solved button.

Oh, I forgot to click that… I do have another question though.
I have an undefined variable. I am thinking it is my substr. Is there a way to correct this?

$phone = substr($contact[7],0,3) . "-" . substr($contract[7],3,4);

is it supposed to be contact or contract just checking

[php]substr($contract[/php]

lol, yes I just seen that. think my eyes are getting bad. it was suppose to be contract.

Did that fix it then ?

Sorry for the late reply Noodle. Yes that did fix the problem.

Sponsor our Newsletter | Privacy Policy | Terms of Service