...

View Full Version : Booking Form Help



roly_33
05-19-2008, 12:02 PM
Hi

I am developing a booking form for a campsite - and have sorted the javascript and thought I had managedt o sort the php too als no - when I submit the form I get a parse error - but the code all seems fine .

Help please..

link to booking form :- http://www.woodyhyde.co.uk/test/booking.html

My Php page is below


<?php
$to = "roly.harrison@gmail.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Online Booking Request";
$fields = array();
$fields{"name"} = "Name:";
$fields{"contact"} = "Contact number:";
$fields{"email"} = "Email:";
$fields{"arrival"} = "Arrival Date:";
$fields{"depart"} = "Departure Date:";
$fields{"nights"} = "No. of Nights:";
$fields{"electric"} = "Electric Hook-up Required:";
$fields{"adults"} = "No. of Adults:";
$fields{"childs"} = "No. of Children:";
$fields{"comment"} = "Additional comments:";
$fields{"group"} = "Group Name:";
$fields{"duke"} = "Duke of Edinburgh:";

$body = "The below information has been sent via the Woodyhyde Website:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("&#37;20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@woodyhyde.fsnet.co.uk";
$subject2 = "Thank you for sending a booking request";
$autoreply = "Thank you for contacting us with your booking request. Somebody will get back to you as soon as possible to confirm your booking, usually within 48 hours. If you have any more questions, please consult our website at http://www.woodyhyde.co.uk";

if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)){print "You have not entered a valid email address. ";
echo "Please go<a href='javascript:history.back(1);'> back to the form</a> and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
if($contact == '') {print "You have not entered a contact number name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.woodyhyde.co.uk/" );}
else
{print "We encountered an error sending your mail, please notify camp@woodyhyde.fsnet.co.uk"; }
}
}
?>



Any help gratefully recieved

Iszak
05-19-2008, 01:19 PM
Firstly use PHP tags secondly PHP ignores white space so you don't ahve to have the condition of an if on one line and these both help spotting errors. You forgot to close the first else


<?php
$to = "roly.harrison@gmail.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Online Booking Request";
$fields = array();
$fields{"name"} = "Name:";
$fields{"contact"} = "Contact number:";
$fields{"email"} = "Email:";
$fields{"arrival"} = "Arrival Date:";
$fields{"depart"} = "Departure Date:";
$fields{"nights"} = "No. of Nights:";
$fields{"electric"} = "Electric Hook-up Required:";
$fields{"adults"} = "No. of Adults:";
$fields{"childs"} = "No. of Children:";
$fields{"comment"} = "Additional comments:";
$fields{"group"} = "Group Name:";
$fields{"duke"} = "Duke of Edinburgh:";

$body = "The below information has been sent via the Woodyhyde Website:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("&#37;20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@woodyhyde.fsnet.co.uk";
$subject2 = "Thank you for sending a booking request";
$autoreply = "Thank you for contacting us with your booking request. Somebody will get back to you as soon as possible to confirm your booking, usually within 48 hours. If you have any more questions, please consult our website at http://www.woodyhyde.co.uk";

if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email))
{
print "You have not entered a valid email address. ";
echo "Please go<a href='javascript:history.back(1);'> back to the form</a> and try again";
}

else
{
if($name == '')
{
print "You have not entered a name, please go back and try again";
}

else
{
if($contact == '')
{
print "You have not entered a contact number name, please go back and try again";
}

else
{
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);

if($send)
{
header( "Location: http://www.woodyhyde.co.uk/" );
}

else
{
print "We encountered an error sending your mail, please notify camp@woodyhyde.fsnet.co.uk";
}
}
}
}
?>


Also instead of gonig if no field else if no feild else you can use elseif e.g. saves a lot of indenting.


<?php
$to = "roly.harrison@gmail.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Online Booking Request";
$fields = array();
$fields{"name"} = "Name:";
$fields{"contact"} = "Contact number:";
$fields{"email"} = "Email:";
$fields{"arrival"} = "Arrival Date:";
$fields{"depart"} = "Departure Date:";
$fields{"nights"} = "No. of Nights:";
$fields{"electric"} = "Electric Hook-up Required:";
$fields{"adults"} = "No. of Adults:";
$fields{"childs"} = "No. of Children:";
$fields{"comment"} = "Additional comments:";
$fields{"group"} = "Group Name:";
$fields{"duke"} = "Duke of Edinburgh:";

$body = "The below information has been sent via the Woodyhyde Website:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@woodyhyde.fsnet.co.uk";
$subject2 = "Thank you for sending a booking request";
$autoreply = "Thank you for contacting us with your booking request. Somebody will get back to you as soon as possible to confirm your booking, usually within 48 hours. If you have any more questions, please consult our website at http://www.woodyhyde.co.uk";

if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email))
{
print "You have not entered a valid email address. ";
echo "Please go<a href='javascript:history.back(1);'> back to the form</a> and try again";
}

else
{
if($name == '')
{
print "You have not entered a name, please go back and try again";
}

elseif($contact == '')
{
print "You have not entered a contact number name, please go back and try again";
}

else
{
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);

if($send)
{
header( "Location: http://www.woodyhyde.co.uk/" );
}

else
{
print "We encountered an error sending your mail, please notify camp@woodyhyde.fsnet.co.uk";
}
}
}
?>

abduraooft
05-19-2008, 01:27 PM
roly_33, please check http://www.codingforums.com/showthread.php?t=68462 to see how to post php codes in this forum.

roly_33
05-19-2008, 09:13 PM
Hi

I have amended as advised - thanks - but still getting a parse error when submitting - If php was not running on the server would I get that error - the server bods say it is running (netbenefit) but Its driving me mad - I have tested it on some free webspace on lycos and its fine...submits and emails are sent...

Any help to relieve my madness - please...(just when I thought I was getting somewhere teaching myself php...) :(

bilginxx
09-08-2008, 08:13 PM
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in contact.php on line 217

hi
what would be the reason ?
thank you very much for your time

<?php
error_reporting(E_ALL);
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Company"} = "Company";
$fields{"sendto"} = "Department";
$fields{"jobtitle"} = "Jobtitle ";
$fields{"salutation"} = "Title ";
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone ";
$fields{"city"} = "City ";
$fields{"state"} = "Country ";
$fields{"street"} = "Address";
$fields{"zip"} = "Post Code ";
$fields{"tprovider"} = "Current Telecom Provider";
$fields{"tspend"} = "Annual Telecom Spend";
$fields{"tlineno"} = "How many Telecom Lines";
$fields{"iprovider"} = "Current Internet Provider";
$fields{"cusers"} = "Number of Computer or Users";
$fields{"icost"} = "Current Internet Monthly Cost";
$fields{"icontract"} = "Broadband Contract End date";
$fields{"premisess"} = "How many premises";
$fields{"."} = ". ";
$fields{"esupplier"} = "Electricity Supplier ";
$fields{"electricityspend"} = "Annual Electricity Spend ";
$fields{"incontractE"} = "Still in Contract ?";
$fields{"datecontracte"} = "When will Elec.cont Expire ?";
$fields{"."} = ". ";
$fields{"gsupplier"} = "Gas Supplier";
$fields{"gasspend"} = "Annual Gas Spend ?";
$fields{"datecontractg"} = "Still in Contract ?";
$fields{"datecontractg"} = "When will Gas.cont Expire ?";
$fields{"gasmeter"} = "Main Meter Point Reference no ";
$fields{"."} = ". ";
$fields{"Message"} = "Message ";
$fields{"."} = ". ";
$fields{"gasmeter0"} = "Gas Meter 0 : ";
$fields{"gasmeter1"} = "Gas Meter 1 : ";
$fields{"gasmeter2"} = "Gas Meter 2 : ";
$fields{"gasmeter3"} = "Gas Meter 3 : ";
$fields{"gasmeter4"} = "Gas Meter 4 : ";
$fields{"gasmeter5"} = "Gas Meter 5 : ";
$fields{"gasmeter6"} = "Gas Meter 6 : ";
$fields{"gasmeter7"} = "Gas Meter 7 : ";
$fields{"gasmeter8"} = "Gas Meter 8 : ";
$fields{"gasmeter9"} = "Gas Meter 9 : ";
$fields{"gasmeter10"} = "Gas Meter 10 : ";
$fields{"gasmeter11"} = "Gas Meter 11 : ";
$fields{"gasmeter12"} = "Gas Meter 12 : ";
$fields{"gasmeter13"} = "Gas Meter 13 : ";
$fields{"gasmeter14"} = "Gas Meter 14 : ";
$fields{"gasmeter15"} = "Gas Meter 15 : ";
$fields{"gasmeter16"} = "Gas Meter 16 : ";
$fields{"gasmeter17"} = "Gas Meter 17 : ";
$fields{"gasmeter18"} = "Gas Meter 18 : ";
$fields{"gasmeter19"} = "Gas Meter 19 : ";
$fields{"Sup1"} = "Meter-1Sup1 ";
$fields{"Sup2"} = "Sup2 ";
$fields{"Sup3"} = "Sup3 ";
$fields{"Sup4"} = "Sup4 ";
$fields{"Sup5"} = "Sup5 ";
$fields{"Sup6"} = "Sup6 ";
$fields{"Sup7"} = "Meter-1Sup7 ";
$fields{"Sup8"} = "Meter-2Sup1 ";
$fields{"Sup9"} = "Sup2 ";
$fields{"Sup10"} = "Sup3 ";
$fields{"Sup11"} = "Sup4 ";
$fields{"Sup12"} = "Sup5 ";
$fields{"Sup13"} = "Sup6 ";
$fields{"Sup14"} = "Meter-2Sup7 ";
$fields{"Sup15"} = "Sup1 ";
$fields{"Sup16"} = "Sup2 ";
$fields{"Sup17"} = "Sup3 ";
$fields{"Sup18"} = "Sup4 ";
$fields{"Sup19"} = "Sup5 ";
$fields{"Sup20"} = "Sup6 ";
$fields{"Sup21"} = "Sup7 ";
$fields{"Sup22"} = "Sup1 ";
$fields{"Sup23"} = "Sup2 ";
$fields{"Sup24"} = "Sup3 ";
$fields{"Sup25"} = "Sup4 ";
$fields{"Sup26"} = "Sup5 ";
$fields{"Sup27"} = "Sup6 ";
$fields{"Sup28"} = "Sup7 ";
$fields{"Sup29"} = "Sup1 ";
$fields{"Sup30"} = "Sup2 ";
$fields{"Sup31"} = "Sup3 ";
$fields{"Sup32"} = "Sup4 ";
$fields{"Sup33"} = "Sup5 ";
$fields{"Sup34"} = "Sup6 ";
$fields{"Sup35"} = "Sup7 ";
$fields{"Sup36"} = "Sup1 ";
$fields{"Sup37"} = "Sup2 ";
$fields{"Sup38"} = "Sup3 ";
$fields{"Sup39"} = "Sup4 ";
$fields{"Sup40"} = "Sup5 ";
$fields{"Sup41"} = "Sup6 ";
$fields{"Sup42"} = "Sup7 ";
$fields{"Sup43"} = "Sup1 ";
$fields{"Sup44"} = "Sup2 ";
$fields{"Sup45"} = "Sup3 ";
$fields{"Sup46"} = "Sup4 ";
$fields{"Sup47"} = "Sup5 ";
$fields{"Sup48"} = "Sup6 ";
$fields{"Sup49"} = "Sup7 ";
$fields{"Sup50"} = "Sup1 ";
$fields{"Sup51"} = "Sup2 ";
$fields{"Sup52"} = "Sup3 ";
$fields{"Sup53"} = "Sup4 ";
$fields{"Sup54"} = "Sup5 ";
$fields{"Sup55"} = "Sup6 ";
$fields{"Sup56"} = "Sup7 ";
$fields{"Sup57"} = "Sup1 ";
$fields{"Sup58"} = "Sup2 ";
$fields{"Sup59"} = "Sup3 ";
$fields{"Sup60"} = "Sup4 ";
$fields{"Sup61"} = "Sup5 ";
$fields{"Sup62"} = "Sup6 ";
$fields{"Sup63"} = "Sup7 ";
$fields{"Sup64"} = "Sup1 ";
$fields{"Sup65"} = "Sup2 ";
$fields{"Sup66"} = "Sup3 ";
$fields{"Sup67"} = "Sup4 ";
$fields{"Sup68"} = "Sup5 ";
$fields{"Sup69"} = "Sup6 ";
$fields{"Sup70"} = "Sup7 ";
$fields{"Sup71"} = "Sup1 ";
$fields{"Sup72"} = "Sup2 ";
$fields{"Sup73"} = "Sup3 ";
$fields{"Sup74"} = "Sup4 ";
$fields{"Sup75"} = "Sup5 ";
$fields{"Sup76"} = "Sup6 ";
$fields{"Sup77"} = "Sup7 ";
$fields{"Sup78"} = "Sup1 ";
$fields{"Sup79"} = "Sup2 ";
$fields{"Sup80"} = "Sup3 ";
$fields{"Sup81"} = "Sup4 ";
$fields{"Sup82"} = "Sup5 ";
$fields{"Sup83"} = "Sup6 ";
$fields{"Sup84"} = "Sup7 ";
$fields{"Sup85"} = "Sup1 ";
$fields{"Sup86"} = "Sup2 ";
$fields{"Sup87"} = "Sup3 ";
$fields{"Sup88"} = "Sup4 ";
$fields{"Sup89"} = "Sup5 ";
$fields{"Sup90"} = "Sup6 ";
$fields{"Sup91"} = "Sup7 ";
$fields{"Sup92"} = "Sup1 ";
$fields{"Sup93"} = "Sup2 ";
$fields{"Sup94"} = "Sup3 ";
$fields{"Sup95"} = "Sup4 ";
$fields{"Sup96"} = "Sup5 ";
$fields{"Sup97"} = "Sup6 ";
$fields{"Sup98"} = "Sup7 ";
$fields{"Sup99"} = "Sup1 ";
$fields{"Sup100"} = "Sup2 ";
$fields{"Sup101"} = "Sup3 ";
$fields{"Sup102"} = "Sup4 ";
$fields{"Sup103"} = "Sup5 ";
$fields{"Sup104"} = "Sup6 ";
$fields{"Sup105"} = "Sup7 ";
$fields{"Sup106"} = "Sup1 ";
$fields{"Sup107"} = "Sup2 ";
$fields{"Sup108"} = "Sup3 ";
$fields{"Sup109"} = "Sup4 ";
$fields{"Sup110"} = "Sup5 ";
$fields{"Sup111"} = "Sup6 ";
$fields{"Sup112"} = "Sup7 ";
$fields{"Sup113"} = "Sup1 ";
$fields{"Sup114"} = "Sup2 ";
$fields{"Sup115"} = "Sup3 ";
$fields{"Sup116"} = "Sup4 ";
$fields{"Sup117"} = "Sup5 ";
$fields{"Sup118"} = "Sup6 ";
$fields{"Sup119"} = "Sup7 ";
$fields{"Sup120"} = "Sup1 ";
$fields{"Sup121"} = "Sup2 ";
$fields{"Sup122"} = "Sup3 ";
$fields{"Sup123"} = "Sup4 ";
$fields{"Sup124"} = "Sup5 ";
$fields{"Sup125"} = "Sup6 ";
$fields{"Sup126"} = "Sup7 ";
$fields{"Sup127"} = "Sup1 ";
$fields{"Sup128"} = "Sup2 ";
$fields{"Sup129"} = "Sup3 ";
$fields{"Sup130"} = "Sup4 ";
$fields{"Sup131"} = "Sup5 ";
$fields{"Sup132"} = "Sup6 ";
$fields{"Sup133"} = "Sup7 ";
$fields{"Sup134"} = "Sup1 ";
$fields{"Sup135"} = "Sup2 ";
$fields{"Sup136"} = "Sup3 ";
$fields{"Sup137"} = "Sup4 ";
$fields{"Sup138"} = "Sup5 ";
$fields{"Sup139"} = "Sup6 ";
$fields{"Sup140"} = "Sup7 ";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);}
$headers2 = "From: diane@lowerprice4u.com ";
$subject2 = "Thank you for contacting us ";
$autoreply = "We appreciate your contact. Please don't reply to this e-mail. We will get back to you as soon as possible, usualy within 48 hours. In the meantime, please enjoy browsing our website at http://www.lowerprice4u.com";
if($from == 'diane@lowerprice4u.com'') {print "You have not entered an email, please go back and try again ";}
else {
{
if($Name == '')
{
print "You have not entered a name, please go back and try again";
}
else
{
$send = mail($to,$subject,$body,$headers,$array,'-fdiane@lowerprice4u.com');
$send2 = mail($from,$subject2,$autoreply,$headers2);
if($send)
{header( "Location: ../thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify diane@lowerprice4u.com "; }
}
}
?>

CFMaBiSmAd
09-08-2008, 08:40 PM
bilginxx, please don't post your question onto the end of an existing thread.

bazz
09-09-2008, 04:28 AM
Hi roly; you seem to have got it working.

I submitted a form with incorrect data and it went through or, it appeared to because it told me it did.

if this interacts with a db, I would recommend that you add more error checking so that dodgey stuff can't be submitted that would clear your db. also, you might want to add a cpatcha system to reduce your bot-generated spam.


bazz

Booking
02-19-2011, 01:26 AM
Nice! thanks for theads up. It's really helpful. I hope to see more updates in coding from this forum. My friends told me that there are a lot of available tutorials in this forum too. thanks.
ubytovanie (http://www.boooking.eu)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum