Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Unexpected $end error

Status
Not open for further replies.

tyrannus

MIS
Apr 6, 2006
115
US
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----->
 
Generally speaking, you get that message when the parser gets to the end of a file, but is still inside a set of {...} bracket. In short, you're missing a "}" somewhere.

A quick look tells me that you are either defining functions within functions, or you forgot the "}" at the end of the definition of mail_form().



Want the best answers? Ask the best questions! TANSTAAFL!
 
Often one error hides another. PHP's parser is multipass...


I don't know. When I attempt to run your code, I get an error on line 26, which is this line:

if($_REQUEST['my_email']!=')

(you're not closing a set of two singlequotes.

Assuming that line 10 is somewhere inside the multiline assignment to $message, it may be that PHP doesn't like your use of associative array references inside a string literal. That can cause problems, so I generally do something like:

$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";





Want the best answers? Ask the best questions! TANSTAAFL!
 
Sorry about my last post.. I was a bit confused.. I changed the code on my local pc but forgot to upload it to the main server so when I tried the page I got that error.. The real error I am getting now is in regards to the line near the bottom that says $result = $db->query($query);
 
Thanks, that is what I thought too but oh well... thanks for your help
 
I meant with it not being unexpected..

I checked out the php site like you suggested and realized I needed to set global $db; in the function that was getting the error
 
I feel like I am having you rewrite the code for me... lol but something else has come up.. just keep getting error after error.. Had I actually written the code I would probably have an easier time fixing it, but I inherited it and was told to make it work.. getting a new error

Warning: mail() [function.mail]: SMTP server response: 501 unacceptable mail address in F:\ on line 19

(code)
$to = 'test1@test.com';
//$to = 'test2@test2.com';
$subject = 'Request for Quote';
$headers = 'From: Prospect';

mail($to, $subject, $message, $headers);

line 19 is the mail($to, $subject, $message, $headers);
 
I don't know what MTA you're using, but it sounds to me like something is blocking your email. Maybe an antispam filter or something....

But I don't think this is a PHP error.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Ok thanks, we are using a barracuda spam filter and our MTA is IMAIL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top