...

View Full Version : Help with online order form i am making



Hughesy1986
10-28-2006, 03:00 PM
Hi guys,

Im am developing a online ordering form for my web hosting company, major problem i am havinf is the way my if statements are working, im pretty new to this and really need some help, you guys will probally spot it instantly.

Heres php code:


<?php
//Take customers details

// Personal Details
$f_name = $_POST['f_name'];
$s_name = $_POST['s_name'];
$email = $_POST['email'];
$c_email = $_POST['c_email'];
$address = $_POST['address'];
$post_code = $_POST['post_code'];

//Hosting Details
$hosting_type = $_POST['hosting_type'];
$length_hosting = $_POST['length_hosting'];
$domain = $_POST['domain'];
$hosting_period = "";

//Payment Details
$payment = $_POST['payment'];
$bill = "";

//Errors
if ($f_name == "")
echo "<font color='#FF0000'>You must enter a first name!</font>";
if ($s_name == "")
echo "<font color='#FF0000'>You must enter a surname!</font>";
if ($email == "")
echo "<font color='#FF0000'>You must enter a email!</font>";
if ($c_email == "")
echo "<font color='#FF0000'>You must confirm your email!</font>";
if ($address == "")
echo "<font color='#FF0000'>You must enter your address</font>";
if ($post_code == "")
echo "<font color='#FF0000'>You must enter a post/zip code!</font>";
if ($hosting_type == "")
echo "<font color='#FF0000'>You must choose a hosting type!</font>";
if ($domain == "")
echo "<font color='#FF0000'>You must enter a domain!</font>";
if ($paypal == "")
echo "<font color='#FF0000'>You must choose a payment type!</font>";
if ($jensleypay == "")
echo "<font color='#FF0000'>You must choose a payment type!</font>";
else
echo "<font color='FF0000'>All information is complete and checked!</font>";
exit;

//Calculate Costs for package
if ($length_hosting == 'month') ($hosting_period == '1 Month');
if ($length_hosting == 'year') ($hosting_period == '1 Year');
if ($length_hosting == 'month' ($hosting_type == 'starter' ($bill == '0.99')));
if ($length_hosting == 'month' ($hosting_type == 'expert' ($bill == '2.99')));
if ($length_hosting == 'year' ($hosting_type == 'starter' ($bill == '10.99')));
if ($length_hosting == 'year' ($hosting_type == 'expert' ($bill == '34.99')));

//Now make custom order page with user submitted information
echo "Thanks for your order $f_name $s_name","<br>";
echo "You have chosen the $hosting type package for $hosting_period","<br>";
echo "Your total bill is $bill";
if ($payment == 'paypal')
echo "You have chosen to use $payment </br>","Currently our paypal automated system is down,</br>" , "Please send the payment via paypals send money option to the account of sales@thehosters.co.uk<br> with the following information: <br> Name: <br> Email <br> Domain <br>";
if ($payment == 'jensleypay')
echo "You have chosen to use $payment</br>","Please visit <a href='credit.php'>Here</a> to make your payment";
else
echo "<font color='#FF0000'>Error with payment selection, please see <a href='support.php'>Support</a> for more help";

it isnt finished yet i am also going to get the form data to go to my email account so i can keep a record.

Many Thanks in advance

Glen

boeing747fp
10-28-2006, 03:13 PM
you need a starting if to use the else statement you are trying to use


<?php
//Take customers details

// Personal Details
$f_name = $_POST['f_name'];
$s_name = $_POST['s_name'];
$email = $_POST['email'];
$c_email = $_POST['c_email'];
$address = $_POST['address'];
$post_code = $_POST['post_code'];

//Hosting Details
$hosting_type = $_POST['hosting_type'];
$length_hosting = $_POST['length_hosting'];
$domain = $_POST['domain'];
$hosting_period = "";

//Payment Details
$payment = $_POST['payment'];
$bill = "";

//Errors
if(empty($f_name) || empty($s_name) || empty($email) || empty($c_email) || empty($address) || empty($post_code) || empty($hosting_type) || empty($domain) || empty($paypal) || empty($jensleypay)){
if ($f_name == ""){
echo "<font color='#FF0000'>You must enter a first name!</font>";
}
if ($s_name == ""){
echo "<font color='#FF0000'>You must enter a surname!</font>";
}
if ($email == ""){
echo "<font color='#FF0000'>You must enter a email!</font>";
}
if ($c_email == ""){
echo "<font color='#FF0000'>You must confirm your email!</font>";
}
if ($address == ""){
echo "<font color='#FF0000'>You must enter your address</font>";
}
if ($post_code == ""){
echo "<font color='#FF0000'>You must enter a post/zip code!</font>";
}
if ($hosting_type == ""){
echo "<font color='#FF0000'>You must choose a hosting type!</font>";
}
if ($domain == ""){
echo "<font color='#FF0000'>You must enter a domain!</font>";
}
if ($paypal == ""){
echo "<font color='#FF0000'>You must choose a payment type!</font>";
}
if ($jensleypay == ""){
echo "<font color='#FF0000'>You must choose a payment type!</font>";
}
exit;
}else{
echo "<font color='FF0000'>All information is complete and checked!</font>";
}


//Calculate Costs for package
if ($length_hosting == 'month') ($hosting_period == '1 Month');
if ($length_hosting == 'year') ($hosting_period == '1 Year');
if ($length_hosting == 'month' ($hosting_type == 'starter' ($bill == '0.99')));
if ($length_hosting == 'month' ($hosting_type == 'expert' ($bill == '2.99')));
if ($length_hosting == 'year' ($hosting_type == 'starter' ($bill == '10.99')));
if ($length_hosting == 'year' ($hosting_type == 'expert' ($bill == '34.99')));

//Now make custom order page with user submitted information
echo "Thanks for your order $f_name $s_name","<br>";
echo "You have chosen the $hosting type package for $hosting_period","<br>";
echo "Your total bill is &#163; $bill";
if ($payment == 'paypal')
echo "You have chosen to use $payment </br>","Currently our paypal automated system is down,</br>" , "Please send the payment via paypals send money option to the account of sales@thehosters.co.uk<br> with the following information: <br> Name: <br> Email <br> Domain <br>";
if ($payment == 'jensleypay')
echo "You have chosen to use $payment</br>","Please visit <a href='credit.php'>Here</a> to make your payment";
else
echo "<font color='#FF0000'>Error with payment selection, please see <a href='support.php'>Support</a> for more help";

Hughesy1986
10-28-2006, 06:24 PM
Thanks for the reply!

Ok i have fixed what you had said, now im getting the following error:


Parse error: syntax error, unexpected '(' in /home/sites/thehosters.co.uk/public_html/forms/order_process.php on line 63



//Calculate Costs for package
if ($length_hosting == 'month') ($hosting_period == '1 Month');
if ($length_hosting == 'year') ($hosting_period == '1 Year');
*** LINE63 *** if ($length_hosting == 'month' ($hosting_type == 'starter' ($bill == '0.99')));
if ($length_hosting == 'month' ($hosting_type == 'expert' ($bill == '2.99')));
if ($length_hosting == 'year' ($hosting_type == 'starter' ($bill == '10.99')));
if ($length_hosting == 'year' ($hosting_type == 'expert' ($bill == '34.99')));

I beleive i am coding this wrong with my ) but im not sure where to place these to get the action i need, can anyone else suggest a better way to code this?

Many Thanks

Glen

Fumigator
10-28-2006, 09:37 PM
if ($length_hosting == 'month') ($hosting_period == '1 Month');

What are you trying to accomplish with this statement? Are you trying to say "if the variable $length_hosting is equal to string 'month', then assign the string '1 Month' to variable $hosting_period"? If that is what you are attempting to say, then you have the syntax wrong.

First, a code block is delimited by {} brackets, not () parenthesis. Second, you don't use double equal signs to assign a value to a variable; use a single equal sign for that. Double equal signs means "is the operator on the left equal to the operator on the right?"

So the correct syntax would be:


if ($length_hosting == 'month') {
$hosting_period = '1 Month';
}

Hughesy1986
10-29-2006, 06:53 AM
Thanks alot fumigator!

+ rep for both who helped me

Many Thanks Glen

EDIT:

Ok, I have made these changes so far here is the whole script:

<?php
//Take customers details

// Personal Details
$f_name = $_POST['f_name'];
$s_name = $_POST['s_name'];
$email = $_POST['email'];
$c_email = $_POST['c_email'];
$address = $_POST['address'];
$post_code = $_POST['post_code'];

//Hosting Details
$hosting_type = $_POST['hosting_type'];
$length_hosting = $_POST['length_hosting'];
$domain = $_POST['domain'];
$hosting_period = "";

//Payment Details
$payment = $_POST['payment'];
$bill = "";

//Errors
if(empty($f_name) || empty($s_name) || empty($email) || empty($c_email) || empty($address) || empty($post_code) || empty($hosting_type) || empty($domain) || empty($paypal) || empty($jensleypay)){
if ($f_name == ""){
echo "<font color='#FF0000'>You must enter a first name!</font>";
}
if ($s_name == ""){
echo "<font color='#FF0000'>You must enter a surname!</font>";
}
if ($email == ""){
echo "<font color='#FF0000'>You must enter a email!</font>";
}
if ($c_email == ""){
echo "<font color='#FF0000'>You must confirm your email!</font>";
}
if ($address == ""){
echo "<font color='#FF0000'>You must enter your address</font>";
}
if ($post_code == ""){
echo "<font color='#FF0000'>You must enter a post/zip code!</font>";
}
if ($hosting_type == ""){
echo "<font color='#FF0000'>You must choose a hosting type!</font>";
}
if ($domain == ""){
echo "<font color='#FF0000'>You must enter a domain!</font>";
}
if ($paypal == ""){
echo "<font color='#FF0000'>You must choose a payment type!</font>";
}
if ($jensleypay == ""){
echo "<font color='#FF0000'>You must choose a payment type!</font>";
}
exit;
}else{
echo "<font color='FF0000'>All information is complete and checked!</font>";
}


//Calculate Costs for package
if ($length_hosting == 'month') {
$hosting_period = '1 Month';
}
if ($length_hosting == 'year') {
$hosting_period = '1 Year';
}
if ($length_hosting == 'month') + ($hosting_type == 'starter') {
$bill = '0.99';
}
if ($length_hosting == 'month') + ($hosting_type == 'expert') {
$bill = '2.99';
}
if ($length_hosting == 'year') + ($hosting_type == 'starter') {
$bill = '10.99';
}
if ($length_hosting == 'year') + ($hosting_type == 'expert') {
$bill = '34.99';
}

//Now make custom order page with user submitted information
echo "Thanks for your order $f_name $s_name","<br>";
echo "You have chosen the $hosting type package for $hosting_period","<br>";
echo "Your total bill is $bill";
if ($payment == 'paypal')
echo "You have chosen to use $payment </br>","Currently our paypal automated system is down,</br>" , "Please send the payment via paypals send money option to the account of sales@thehosters.co.uk<br> with the following information: <br> Name: <br> Email <br> Domain <br>";
if ($payment == 'jensleypay')
echo "You have chosen to use $payment</br>","Please visit <a href='credit.php'>Here</a> to make your payment";
else
echo "<font color='#FF0000'>Error with payment selection, please see <a href='support.php'>Support</a> for more help";

?>

Now on line 67 it is saying that Parse error: syntax error, unexpected '{'

Im guessing that
if ($length_hosting == 'month') + ($hosting_type == 'starter') {
$bill = '0.99';
}

I have coded this wrong somewhere? maybe the ) + ( ??im really confused please help!

Many Thanks Glen

airoid
10-29-2006, 07:20 AM
Are you trying to say if the length of hosting is monthly and the type is starter then the cost is $.99?

You would say "AND" instead of using a + sign.

Hughesy1986
10-29-2006, 07:24 AM
Hi,

Yes im thats exactly it.


Parse error: syntax error, unexpected T_LOGICAL_AND

Is this coded right? do I have to have some kind of brackets around the AND operator?


//Calculate Costs for package
if ($length_hosting == 'month') {
$hosting_period = '1 Month';
}
if ($length_hosting == 'year') {
$hosting_period = '1 Year';
}
if ($length_hosting == 'month') AND ($hosting_type == 'starter') {
$bill = '0.99';
}
if ($length_hosting == 'month') AND ($hosting_type == 'expert') {
$bill = '2.99';
}
if ($length_hosting == 'year') AND ($hosting_type == 'starter') {
$bill = '10.99';
}
if ($length_hosting == 'year') AND ($hosting_type == 'expert') {
$bill = '34.99';
}

boeing747fp
10-29-2006, 02:44 PM
you need some elseif()s in there in the place of some of your if()s... and when you do a multi-part if statement (ANDs or ORs) you do not close the parenthasis to the if() to put the AND in...

try this:


//figure out what the billing period is
if ($length_hosting == 'month') {
$hosting_period = '1 Month';
}
elseif ($length_hosting == 'year') {
$hosting_period = '1 Year';
}

//separate if/else statements for the bill price
if ($length_hosting == 'month' AND $hosting_type == 'starter') {
$bill = '0.99';
}
elseif ($length_hosting == 'month' AND $hosting_type == 'expert') {
$bill = '2.99';
}
elseif ($length_hosting == 'year' AND $hosting_type == 'starter') {
$bill = '10.99';
}
elseif ($length_hosting == 'year' AND $hosting_type == 'expert') {
$bill = '34.99';
}

Hughesy1986
10-29-2006, 05:16 PM
Hey thanks for all your help!

Works fine got some rough around the edges but it works thats the main thing.

You can view it http://www.thehosters.co.uk/order1.html

Many Thanks Again

Glen

Hughesy1986
10-29-2006, 05:39 PM
Now that is all working, I am sending the whole data to my email account, using this code


mail('admin@thehosters.co.uk', 'Hosting Signup', 'We have had a new client signup for webhosting<br> $package, $hosting_period, $bill, $payment, $email');

Im not sure why but none of my variables are being included in the email.

all im receiving is this


We have had a new client signup for webhosting<br> $package, $hosting_period, $bill, $payment, $email

Is it something to do with [ bit? i was reading on the php manual this, but it wasnt making much sense

Fumigator
10-30-2006, 12:44 AM
The PHP processor will interpret variables imbedded in a string only if you use the double quotes. Otherwise it will treat the variable name as a literal.

Example:



$hello = 'hi there ';
$world = 'earth';
echo '$hello $world'; //echos string '$hello $world'
echo "$hello $world"; //echos string 'hi there earth'


You don't have to imbed variables in a string; you can concantenate them like this:



$disease1 = 'worms';
$disease2 = 'whooping cough';
echo 'my dog has ' . $disease1 . ' and my grandma has ' . $disease2;


For your specific case I think just using double quotes will get you where you want to go.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum