I have no idea why I am getting this error.. it always points to the last line of the script which is the ?> . What happens is on a previous page a user fills out information in a form, then when they hit submit this code runs. But, I always get a syntax error unexpected $end on line whatever.. I am new to php so I am not too familiar with all there is.. below is my code.. if anyone can help I really do appreciate it..
<---- begin code here---->
<?php
$db = new mysqli('localhost','silver','ziplook', 'silvertr_ziplookup') or die('Could not connect: ' . mysql_error());
function mail_form($data) {
$datetime = date("r");
$message = "===========================================\nContact
Message\n===========================================\nContact
Name:\t$data[Sender]\nContact Method:\t$data[Method]\nContact
Info:\t$data[Info]\nCargo:\t$data[Cargo]\n\nPick-Up
From:\n-----------------------\nCountry:\t$data[Country]\nState:\t$data
[State]\nCity:\t$data[City]\nZipcode:\t$data[Zipcode]\n\nDeliver To:\n-----------------------\nCountry:\t$data[Destcountry]\nState:\t$data
[Deststate]\nCity:\t$data[Destcity]\nZipcode:\t$data[Destzip]\n\nPick-up Time:\n-----------------------\nDate:\t$data[Ready]\nTime:\t$data[PickupBy]
\n\nDelivery Deadline:\n-----------------------\nDate:\t$data[Expected]\nTime:\t$data
[DeliverBy]\nDate/Time Sent:\t$datetime\n";
$to = 'test1@test.com';
//$to = 'test2@test2.com';
$subject = 'Request for Quote';
$headers = 'From: Prospect';
mail($to, $subject, $message, $headers);
if($_REQUEST['my_email']!=')
{
$to = $_REQUEST['my_email'];
$subject = 'Copy of Complete Logistics Contact Form';
mail($to, $subject, $message, $headers);
}
function check_fields($city,$state,$zip)
{
$error_flag = false;
//print $city.$state.$zip;
if(!preg_match("/^\d\d\d\d\d/",$zip))
{
$error_flag = true;
$error_message .= 'Please Enter a Zip Code.';
}
elseif(( $city==' || $city=='Enter City or Town' ) && $state==')
{
$info_array = query_zip($zip);
//print_r($info_array);
if($info_array!='error')
{
$city = ucwords(strtolower($info_array['city']));
$state = $info_array['state'];
}
else
{
$error_flag = true;
$error_message .= ' Invalid Zip Code Entered';
}
}
elseif(( $city==' || $city=='Enter City or Town' ) && $state!=')
{
$info_array = query_zip($zip);
if($info_array!='error' && $state==$info_array['state'])
$city = ucwords(strtolower($info_array['city']));
else
{
$error_flag = true;
$error_message .= ' Zip Code and State do not match.';
}
}
elseif(( $city!=' || $city!="Enter City or Town" ) && $state==')
{
//print ".$city. - Enter City or Town<br>";
$info_array = query_zip($zip);
if($info_array!='error' && strtolower($city)==strtolower($info_array['city']))
{
$city = ucwords(strtolower($info_array['city']));
$state = $info_array['state'];
}
else
{
$error_flag = true;
$error_message .= ' Zip Code and City do not match.';
}
}
elseif(( $city!=' || $city!='Enter City or Town' ) && $state!=')
{
$info_array = query_zip($zip);
if($info_array!='error' && $state==$info_array['state'] && strtolower($city)==strtolower($info_array['city']))
{
$city = ucwords(strtolower($info_array['city']));
$state = $info_array['state'];
}
else
{
$error_flag = true;
$error_message .= ' Wrong zip code for this city.';
}
}
}
if($error_flag==true)
{
$return['error'] = $error_message;
}
else
{
$return['zip'] = $zip;
$return['city'] = $city;
$return['state'] = $state;
}
return $return;
function query_zip($zip)
{
$query = "SELECT * FROM zipcodes WHERE zip = '".$zip."'";
$result = $db->query($query);
if(mysqli_num_rows($result)>0)
{
$row = mysqli_fetch_assoc($result);
$return_array['city'] = $row['city'];
$return_array['state'] = $row['state'];
}
else
$return_array = 'error';
return $return_array;
}
?>
<------end of code----->
<---- begin code here---->
<?php
$db = new mysqli('localhost','silver','ziplook', 'silvertr_ziplookup') or die('Could not connect: ' . mysql_error());
function mail_form($data) {
$datetime = date("r");
$message = "===========================================\nContact
Message\n===========================================\nContact
Name:\t$data[Sender]\nContact Method:\t$data[Method]\nContact
Info:\t$data[Info]\nCargo:\t$data[Cargo]\n\nPick-Up
From:\n-----------------------\nCountry:\t$data[Country]\nState:\t$data
[State]\nCity:\t$data[City]\nZipcode:\t$data[Zipcode]\n\nDeliver To:\n-----------------------\nCountry:\t$data[Destcountry]\nState:\t$data
[Deststate]\nCity:\t$data[Destcity]\nZipcode:\t$data[Destzip]\n\nPick-up Time:\n-----------------------\nDate:\t$data[Ready]\nTime:\t$data[PickupBy]
\n\nDelivery Deadline:\n-----------------------\nDate:\t$data[Expected]\nTime:\t$data
[DeliverBy]\nDate/Time Sent:\t$datetime\n";
$to = 'test1@test.com';
//$to = 'test2@test2.com';
$subject = 'Request for Quote';
$headers = 'From: Prospect';
mail($to, $subject, $message, $headers);
if($_REQUEST['my_email']!=')
{
$to = $_REQUEST['my_email'];
$subject = 'Copy of Complete Logistics Contact Form';
mail($to, $subject, $message, $headers);
}
function check_fields($city,$state,$zip)
{
$error_flag = false;
//print $city.$state.$zip;
if(!preg_match("/^\d\d\d\d\d/",$zip))
{
$error_flag = true;
$error_message .= 'Please Enter a Zip Code.';
}
elseif(( $city==' || $city=='Enter City or Town' ) && $state==')
{
$info_array = query_zip($zip);
//print_r($info_array);
if($info_array!='error')
{
$city = ucwords(strtolower($info_array['city']));
$state = $info_array['state'];
}
else
{
$error_flag = true;
$error_message .= ' Invalid Zip Code Entered';
}
}
elseif(( $city==' || $city=='Enter City or Town' ) && $state!=')
{
$info_array = query_zip($zip);
if($info_array!='error' && $state==$info_array['state'])
$city = ucwords(strtolower($info_array['city']));
else
{
$error_flag = true;
$error_message .= ' Zip Code and State do not match.';
}
}
elseif(( $city!=' || $city!="Enter City or Town" ) && $state==')
{
//print ".$city. - Enter City or Town<br>";
$info_array = query_zip($zip);
if($info_array!='error' && strtolower($city)==strtolower($info_array['city']))
{
$city = ucwords(strtolower($info_array['city']));
$state = $info_array['state'];
}
else
{
$error_flag = true;
$error_message .= ' Zip Code and City do not match.';
}
}
elseif(( $city!=' || $city!='Enter City or Town' ) && $state!=')
{
$info_array = query_zip($zip);
if($info_array!='error' && $state==$info_array['state'] && strtolower($city)==strtolower($info_array['city']))
{
$city = ucwords(strtolower($info_array['city']));
$state = $info_array['state'];
}
else
{
$error_flag = true;
$error_message .= ' Wrong zip code for this city.';
}
}
}
if($error_flag==true)
{
$return['error'] = $error_message;
}
else
{
$return['zip'] = $zip;
$return['city'] = $city;
$return['state'] = $state;
}
return $return;
function query_zip($zip)
{
$query = "SELECT * FROM zipcodes WHERE zip = '".$zip."'";
$result = $db->query($query);
if(mysqli_num_rows($result)>0)
{
$row = mysqli_fetch_assoc($result);
$return_array['city'] = $row['city'];
$return_array['state'] = $row['state'];
}
else
$return_array = 'error';
return $return_array;
}
?>
<------end of code----->