Forum Moderators: coopster

Message Too Old, No Replies

PHP and check box calculations

Discounts page calculation

         

taimur23

3:43 pm on Apr 24, 2006 (gmt 0)



I am trying to calculate discounts on a boat using check box's.
The way they work is: if 2 options are selected i need to multiply each option selected by $o2ptions.

And if all 3 are selected i need to see if its cheaper to use
a) $o3ptionsA = multiply all options by 0.85 and add to yacht price
b) $o3ptionsB = multiply boat price by 1.005 and add full option prices.

I have no idea how to do this, but i cannot use Java.
any help appreciated.
Thanks

<HTML>
<HEAD>
<TITLE> Ocean Breeze Discount</TITLE>
<Head>
<BODY>
<FORM METHOD="post" ACTION=post>
<?

$bName = "Ocean Breeze 44";
$bPrice = "£558,000";
$option1 = "440";
$option2 = "260";
$option3 = "300";

$o2ptions = "0.9";
$o3ptionsA = "0.85";
$o3ptionsB = "1.005";

echo "<p>Yacht Name: $bName</P>";
echo "<p>Yacht costs: $bPrice</P>";

?>

<P>Discounts:<br>
<INPUT TYPE="checkbox" NAME="calc" VALUE="option1"> Food & beverage hamper £440<br>
<INPUT TYPE="checkbox" NAME="calc" VALUE="option2"> 2 person fully equipped snorkel kit £260<br>
<INPUT TYPE="checkbox" NAME="calc" VALUE="option3"> Entertainment pack (X Box 360) £300<br>


<P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></P>
</FORM>

</BODY>
</Head>
</HTML>

jatar_k

6:46 pm on Apr 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld taimur23,

first you would need to change the action of your form to point to a php script.

At that point once the form is submitted the values entered into your form would become available to your script in the $_POST superglobal array.

You could try looking at this thread for the basics of dealing with form submissions.

[webmasterworld.com...]

this deals with emailing the results but you can ignore that and look at how the values from the form are processed.

this manual link will help also
[php.net...]