SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict Owz2004's Avatar
    Join Date
    Mar 2004
    Location
    U.K (Wales)
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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 £1.95 and the postage is £1.99
    11 - 20 the price per item is £1.75 and the postage is £3.95
    21 - 50 the price per item is £1.55 and the postage is £4.95
    51 - 100 the price per item is £1.35 and the postage is £6.95
    101 + the price per item is £1.25 and the postage is £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:

    PHP Code:
    print '. $title .' "X" '. qty .' "at" '. $price .' "plus" '. $postage .' "post and packaging = £" '. $total .' 
    The title and id variables are from a database where the product is located.

    Its the other variables that I want to also output from the form. I want the sentance to read back to the user as

    product title X 5 at &#163;1.95 plus &#163;1.99 postage and packaging = &#163;11.74

    Any help would be greatly appreciated...

    O

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    PHP Code:
    if(isset($_POST['qty'])) {
        
    $qty $_POST['qty'];

        if(
    $qty 100) {
            
    $postage 7.95;
            
    $price 1.25;
        } else if(
    $qty 50) {
            
    $postage 6.95;
            
    $price 1.35;
        } else if(
    $qty 20) {
            
    $postage 4.95;
            
    $price 1.55;
        } else if(
    $qty 10) {
            
    $postage 3.95;
            
    $price 1.75;
        } else {
            
    $postage 1.99;
            
    $price 1.95;
        }
                            
        
    $total $qty $price $postage
    Now, what was your question? I didn't understand it. Try explaining in more detail.

    Nice design, by the way.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2007
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $total should be $total = ($qty * $price) + $postage;

    print statement should be :

    print $title . 'X' . $qty . ' at ' . $price . ' plus ' . $postage . ' post and packaging = ' . $total;

  4. #4
    SitePoint Addict Owz2004's Avatar
    Join Date
    Mar 2004
    Location
    U.K (Wales)
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because Im really new to php and I get confused easily..

    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.

    does this make sense?

    thanks for the compliment by the way

  5. #5
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So in orderform.php you have the code above? If yes then you're pretty much set. Just add the echo statement wherever you want it to display the order summary:

    PHP Code:
    echo $title' &times; '$qty' at &pound;'$price' + &pound;'$postage' postage and packaging = &pound;'$total

  6. #6
    SitePoint Addict Owz2004's Avatar
    Join Date
    Mar 2004
    Location
    U.K (Wales)
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    on the first page the form is as follows

    HTML Code:
    <form name="addqty" method="post" action="orderform.php">
    							
    <label name="quantity">Quantity:</label>
    <input name="qty" type="text" size="5"/><br />
    <input type="submit" class="submit" value="Proceed" name="submit" />
    							
    </form>
    that then submits the form to the 2nd page (orderform.php)

    which has up at the top of the code:

    PHP Code:
    <?php


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

        if(
    $qty 100) {
            
    $postage 7.95;
            
    $price 1.25;
        } else if(
    $qty 50) {
            
    $postage 6.95;
            
    $price 1.35;
        } else if(
    $qty 20) {
            
    $postage 4.95;
            
    $price 1.55;
        } else if(
    $qty 10) {
            
    $postage 3.95;
            
    $price 1.75;
        } else {
            
    $postage 1.99;
            
    $price 1.95;
        }
                            
        
    $total = ($qty $price) + $postage
                
        }
            
       
    ?>
    then further down in the page I have the following code:

    PHP Code:
    <?php print $title 'X' $qty ' at ' $price ' plus ' $postage ' post and packaging = ' $total?>
    will this do it?

  7. #7
    SitePoint Addict Owz2004's Avatar
    Join Date
    Mar 2004
    Location
    U.K (Wales)
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works guys... thats awesome.. thank you so much...

    Do you know how I would go about having an order acknoledgment to the customer after they fill out the form on the second page?

    I.e as soon as they submit the form with all their details and they pay via paypal... on return they have a acknowledgment sent back to them?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •