Jump to content

Keep getting an error??


mehole

Recommended Posts

I am very new to php so go easy if these mistakes are stupid  ;)
I've got this script:
[code]<?PHP

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$wmonth = $_POST['month'];
$wdate = $_POST['date'];
$wyear = $_POST['year'];
$umonth = $_POST['month2'];
$udate = $_POST['date2'];
$uyear = $_POST['year2'];
$adults = $_POST['adults'];
$child = $_POST['child'];
$submit = $_POST['submit'];

//enter the email that the form should be sent to
$emailTo = 'my@email.com';
//enter the email's subject
$emailSubject = "Email subject";

$emailBody = "Name: $fname $lname\n";
"Email: $email\n";
"Phone Number: $phone\n";
"Dates wanted: $wmonth-$wdate-$wyear\n";
"Until: $umonth-$udate-$year";
"Number of Adults: $adults";
"Number of Children: $child";

$emailHeader = "From: $fname $lname; $email\n";
"Reply-To: $fname $lname\n";
"MIME-Version: 1.0\n";
"Content-type: text/plain; charset=\"ISO-8859-1\"\n";
"Content-transfer-encoding: quoted-printable\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

if ($_POST['submit']) {

if (($fname=="") || ($lname=="")|| ($email=="") || ($wmonth=="") || ($wdate=="") || ($wyear=="") || ($umonth=="") || ($udate=="") || ($uyear=="") || ($adults==""))  {
print "Error: Please complete all of the required fields.";
outputform();
}

else {
//URL of where the user is redirected to
header("Location: http://www.mysite.com");
exit;
}
?>[/code]

But i keep getting this error:
[quote]Parse error: parse error, unexpected $ in /home/content/m/e/h/mehole8338/html/Bookingform/enquiry.php on line 51[/quote]

But all that is on line 51 is [code]?>[/code]
so i don't understand what is wrong?
Can someone help me out?
Many thanks
Mike
Link to comment
Share on other sites

I'm pretty sure:

[code]
$emailBody = "Name: $fname $lname\n";
"Email: $email\n";
"Phone Number: $phone\n";
"Dates wanted: $wmonth-$wdate-$wyear\n";
"Until: $umonth-$udate-$year";
"Number of Adults: $adults";
"Number of Children: $child";
[/code]

Should Be:

[code]
$emailBody = "Name: $fname $lname\n
Email: $email\n
Phone Number: $phone\n
Dates wanted: $wmonth-$wdate-$wyear\n
Until: $umonth-$udate-$year
Number of Adults: $adults
Number of Children: $child";
[/code]

Also, change:

[code]
if ($_POST['submit']) {
[/code]

To:

[code]
if (isset($_POST['submit'])) {
[/code]

edit (after seeing scott's reply)-

Change:

[code]
$emailHeader = "From: $fname $lname; $email\n";
"Reply-To: $fname $lname\n";
"MIME-Version: 1.0\n";
"Content-type: text/plain; charset=\"ISO-8859-1\"\n";
"Content-transfer-encoding: quoted-printable\n";
[/code]

To:

[code]
$emailHeader .= "From: $fname $lname; $email\n"
."Reply-To: $fname $lname\n"
."MIME-Version: 1.0\n"
."Content-type: text/plain; charset=\"ISO-8859-1\"\n"
."Content-transfer-encoding: quoted-printable\n";
[/code]
Link to comment
Share on other sites

Yeah, you need to sort your strings out, there's no need for closing the quotes and adding the semicolon, just wrap the whole string in a set of quotes.  you do the same for your e-mail header variable too, change it so that the string is wrapped in quotes, without the semicolons at the end, like hostfreak said.
Link to comment
Share on other sites

Ok, i've changed what you said but i'm still getting the same error:

[quote]Parse error: parse error, unexpected $ in /home/content/m/e/h/mehole8338/html/Bookingform/enquiry.php on line 51
[/quote]
I dont understand what's wrong?
Link to comment
Share on other sites

you are missing a closing '}' on your if statement

change
[code]
<?php
if ($_POST['submit']) {

if (($fname=="") || ($lname=="")|| ($email=="") || ($wmonth=="") || ($wdate=="") || ($wyear=="") || ($umonth=="") || ($udate=="") || ($uyear=="") || ($adults==""))  {
print "Error: Please complete all of the required fields.";
outputform();
}

else {
//URL of where the user is redirected to
header("Location: http://www.mysite.com");
exit;
}
?>
[/code]

to

[code]
<?php
if ($_POST['submit']) {

if (($fname=="") || ($lname=="")|| ($email=="") || ($wmonth=="") || ($wdate=="") || ($wyear=="") || ($umonth=="") || ($udate=="") || ($uyear=="") || ($adults==""))  {
print "Error: Please complete all of the required fields.";
outputform();
}

else {
//URL of where the user is redirected to
header("Location: http://www.mysite.com");
exit;
}
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.