Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: PHP Confirmation Page

  1. #1
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Confirmation Page

    Hello all, im really new to php, i know a couple of basic things, but thats about it. I am making a page where you can build a custom computer and when you click the Build button, it takes you to a page that pretty much displays all of the information you selected on the previous page, confirming your order. My page is here:
    http://www.oharanetworks.com/jcr/build/test.htm
    When you click build, I have a simple php page that i want to display the actual name of the processor as on the previous page, but I can only get it to display the value on the page. Im using this
    PHP Code:
    <?php echo $_GET["processor"]; ?>
    But I want to get it to say the name of the processor too, not just the price.
    Anyhelp is requested. Thank you in advanced.

  2. #2
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No one knows how to display form data on another page using "get" method? Help please.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Using your operating systems as an example, because there are comfortably few and I want to make a point, I suggest you do something like this:
    Code:
    <select size="1" name="os" onchange="this.form.c14.value=this.options[this.selectedIndex].value;calculate()">
      <option selected value="os0">Microsoft Windows XP Professional w/ SP2 [Included in Price]</option>
      <option value="os1">Microsoft Windows XP Home Edition w/ SP2 [Subtract $45]</option>
      <option value="os2">Gentoo Linux [Subtract $125]</option>
      <option value="os3">Fedora Core 5 [Subtract $130]</option>
      <option value="os4">No OS [Subtract $135]</option>
    </select>
    Then, in your PHP:
    Code:
    $oses = array(
      "os0" => array(
        "name" => "Microsoft Windows XP Professional Edition SP2",
        "price" => 135.0
      ),
      "os1" => array(
        "name" => "Microsoft Windows XP Home Edition SP2",
        "price" => 90.0
      ),
      "os2" => array(
        "name" => "Gentoo Linux",
        "price" => 10.0
      ),
      "os3" => array(
        "name" => "Fedora Core 5",
        "price" => 5.0
      ),
      "os4" => array(
        "price" =>"No OS",
        "name" => 0.0
      )
    );
    echo("OS: " . $oses[$_GET['os']]['name'] . " (\$" . $oses[$_GET['os']]['price'] . ");");
    You really ought to include some non-Windows OSes in there, and a no-OS option.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Great Idea! Thanks for all your help!

    But there is only one problem, I need to have the price of the OS in the "value" section of the drop down box in order for the calculator to work.

    I have no idea how to fix this, all help is welcomed. Thanks again though.
    Last edited by viper102464; 06-11-2006 at 07:43 AM.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    <option value="135">No OS [Subtract $135]</option>


    ...?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, but if i put the price as the value, the calculator will work, but then twey's code no longer works because the values are no longer os0, os1, os2, os3, and os4, they are different prices. Thus the php will no longer work. I need the calculator and the php script to both work. That's what i was unsure how to do.

    Thanks, and please help.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hm... it's tricky. You could pass the price as the value, but then it becomes confusing if you have two items with the same price.
    I suggest you modify the calculator. Post it here and we'll have a butcher's.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here is the calculator script that jscheuer1 helped me with:

    Code:
    <script language="javascript">
    function cent(amount) { return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount); } function calculate() { var p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14; p1 = xseven.c1.value * 1; p2 = xseven.c2.value * 1; p3 = xseven.c3.value * 1; p4 = xseven.c4.value * 1; p5 = xseven.c5.value * 1; p6 = xseven.c6.value * 1; p7 = xseven.c7.value * 1; p8 = xseven.c8.value * 1; p9 = xseven.c9.value * 1; p10 = xseven.c10.value * 1; p11 = xseven.c11.value * 1; p12 = xseven.c12.value * 1; p13 = xseven.c13.value * 1; p14 = xseven.c14.value * 1; total_price = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14; xseven.total_price.value = cent(Math.round(total_price*Math.pow(10,2))/Math.pow(10,2)); } </script>
    And here is the code for one of the drop down boxes:
    HTML Code:
    <select size="1" name="processor" onchange="this.form.c3.value=this.options[this.selectedIndex].value;calculate()">
    <option value="639.00">AMD Athlon 64 FX55 San Diego 2000MHz HT Socket 939 [Subtract $172] </option>
    <option value="811.00" selected>AMD Athlon 64 FX57 San Diego 2000MHz HT Socket 939 [Included in Price] </option>
    <option value="853.00">AMD Athlon 64 FX60 Toledo 2000MHz HT Socket 939 Dual Core [Add $42] </option>
    </select>
    I used hidden values for the initial prices of all the items so that it would already have an initial price calculated.

    Thanks again for all of your help!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You could just have a bunch of ifs:

    <?php
    if ($_GET['thing'] == "thing") {
    $price = 135;
    }
    elseif (.....
    ?>

    Something like that, and just repeat for each item.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Drop the client-side calculation routine. You say John wrote this? It certainly doesn't look like his style -- and that's a compliment to him.
    Your PHP script:
    Code:
    <?php
    function toCurrency($amount) {
      $amount *= 100;
      $amount = round($amount);
      $amount /= 100;
      if(strpos($amount, ".") === false)
        return $amount . ".00";
      while(strlen(substr($amount, ".")) < 2)
        $amount .= "0";
      return $amount;
    }
    
    function getSelectedItems($items) {
      $si = array();
      foreach($_GET as $k => $v)
        if(isset($items[$v])) array_push($si, $items[$v]);
      return $si;
    }
    
    function formatItemList($items) {
      $si = getSelectedItems($items);
      $rt = 0;
      $html = "<table><tr><th>Item</th><th>Price</th><th>Running Total</th></tr>";
      for($i = 0; $i < count($si); ++$i)
        $html .= "<tr><td>" . $si[$i]['name'] . "</td><td>" . $si[$i]['price'] . "</td><td>" . ($rt += $si[$i]['price']) . "</tr>";
      $html .= "<tr><td>Total</td><td>$rt</td><td>$rt</td></tr></table>";
    }
    
    $items = array(
      "os0" => array(
        "name" => "Microsoft Windows XP Professional Edition SP2",
        "price" => 135.0
      ),
      "os1" => array(
        "name" => "Microsoft Windows XP Home Edition SP2",
        "price" => 90.0
      ),
      "os2" => array(
        "name" => "Gentoo Linux",
        "price" => 10.0
      ),
      "os3" => array(
        "name" => "Fedora Core 5",
        "price" => 5.0
      ),
      "os4" => array(
        "name" =>"No OS",
        "price" => 0.0
      ),
      "cpu0" => array(
        "name" => "AMD Athlon 64 FX55 San Diego 2000MHz HT Socket 939",
        "price" => 639.0
      ),
      "cpu1" => array(
        "name" => "AMD Athlon 64 FX57 San Diego 2000MHz HT Socket 939",
        "price" => 811.0
      ),
      "cpu2" => array(
        "name" => "AMD Athlon 64 FX60 Toledo 2000MHz HT Socket 939 Dual Core",
        "price" => 853.0
      )
      // Add more.  Doesn't matter what the names are, so long as they match the values on the form.
    );
    
    echo(formatItemList($items));
    ?>
    Has the added advantage of being easier to convert to using a database when you decide to do this properly.

    Untested.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •