The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Processing variables from 2 forms using PHP

Hi,

Im learning to use php to transfer vaiables between forms and I'm stuck trying to do something for a project.

I have an input box in a form which is named 'qty' this captures the quantity of a product. this is followed by a submit button which sends the user to an order form to fill out the rest of their details.

on the first page the value inserted into this input box within the form dictates the cost of the postage and the price of the product.

The break down is as follows.

if the person enters between:

1 - 10 the price per item is &#163;1.95 and the postage is &#163;1.99
11 - 20 the price per item is &#163;1.75 and the postage is &#163;3.95
21 - 50 the price per item is &#163;1.55 and the postage is &#163;4.95
51 - 100 the price per item is &#163;1.35 and the postage is &#163;6.95
101 + the price per item is &#163;1.25 and the postage is &#163;7.99

I have created the following code to capture this information:

PHP Code:

<?php

if(isset($_POST['qty'])) {

$qty = $_POST['qty'];

if($qty < 11)$postage = '1.99' || $price = '1.95';

if(($qty < 20) || ($qty > 11))$postage = '3.95' || $price = '1.75';

if(($qty < 50) || ($qty > 21))$postage = '4.95' || $price = '1.55';

if(($qty < 100) || ($qty > 51))$postage = '6.95' || $price = '1.35';

if($qty > 100)$postage = '7.95' || $price = '1.25';

$total = $qty * $price . $postage;

?>

would this be o.k to use to capture the prices and then use to output a sentance on the top of the next page similar to this:

Why are you using logical or operator in the lines where you assign $postage and $price? And why are you assigning them strings?

Also in your if condition you have logical errors (using > 11 etc. where you should be using >= 11 or > 10). And your formatting is really bad. And you're using concatenation operator when adding $postage to $total. OK, enough picking on you

When the purple button is selected on that page it then loads the ordeform.php page which looks like the following:

where you see the gap between the sentance "thank you for choosing blah blah blah" and the first input box I want a sentance which pulls the variables from the previous pages values...

So say we inserted 10 into the qty and hit the submit button, it would then load this page and would give a break down to the user the price of the bars of choc and the postage etc...

The user could then go ahead and fill out their details this would then be submitted to the owner of the site and then they would be redirected to a pay pal screen with the total price of the goods and costs of postage. They would then be able to check out using paypals api.