2013-03-17 73 views
-1

我有形式和PHP,表單詢問用戶他想要購買什麼,用戶選擇它並添加它,我希望它,以便當點擊提交按鈕時,數據存儲在提交按鈕下面顯示了php的可變參數,但我不知道該怎麼做!窗體在PHP和提交按鈕?

<p><b>Billing Information</b></p> 
    <form action="" method="get"> 

     <p>Name: 
    <input type="text" name="firstname"> 
    <br> 
     <strong>Items:</strong></p> 
    </form> 
    <form id="form1" method="post" action=""> 
     <p> 
     <input type="checkbox" name="one" value= "2.39"/> 
     <label for="one">Four 100-watt light bulbs for $2.39</label> 
     <p> 
    <input type="checkbox" name="two" value= "4.29"/> 
    <label for="two">Eight 100-watt light bulbs for $4.29</label> 
    <p> 
     <input type="checkbox" name="three" value= "3.95"/> 
    <label for="three">Four 100-watt long-life light bulbs for $3.95</label> 
     </p> 
     <p> 
     <input type="checkbox" name="four" value= "7.49"/> 
    <label for="four">Eight 100-watt long-life light bulbs for $7.49</label> 
    </p> 
      <input name="battery" name = "battery" type="number" id="battery" size="1" maxlength="3" /> 
<label for="battery">Battery Packs Checkbox $10.42 each:</label> 
     </p> 
     <p><strong><b>Card Details</b>:</strong></p> 
<p> 
    <?php 
    if(isset($_POST['value'])) 
    { 
     $one = $_POST['one']; 
     $two = $_POST['two']; 
     $three = $_POST['three']; 
     $four = $_POST['four']; 
     $five = $_POST['battery']; 

    $total = $one + $two + $three + $four + $battery; 
    $interest = $total * 0.175; 
    echo "Total cost is " .$total; 
    } 
    ?> 
    </p> 
     <p> 
     <p> 
    <input name="Visa" type="radio" value= <?php $cardone = "Visa"; ?> 
    <p>Visa</p> 
    <p> 
      <input name="Mastercard" type="radio" value= <?php $cardtwo = "Mastercard"; ?> 
     <p>Mastercard</p> 
    <p> 
      <input name="American" type="radio" value=<?php $cardthree = "American Express"; ?> 
     <p> American Express </p> 
<p> 
    <?php 
    if(isset($_POST['value'])) 
    { 
     $cardone = $_POST['cardone']; 
     $cardtwo = $_POST['cardtwo']; 
     $cardthree = $_POST['cardthree']; 
    $total = $cardone + $cardtwo + $cardthree; 
    echo "You have chose to pay using a " .$total; 
    } 
    ?> 
<input type="Submit" name="SubmitForm" value="Submit"> 
<form action="Results.php" method="post"> 
<input name="Submit" type="button" /> 
</p> 
</form> 

對不起,如果這沒有出來好,但HTML的東西不是很好。請幫幫我!

+0

您必須將表單提交到新頁面,否則無法從同一頁面上的值獲取'$ _POST'。 – 2013-03-17 16:03:00

+1

'$ _POST ['cardone']是什麼?這個名字沒有表單字段,名字是'Mastercard'。爲什麼要添加這些字段,它們不是數字? – Barmar 2013-03-17 16:03:04

+0

首先,你有''OUTSIDE你的'

2013-03-17 16:04:20

回答

1

沒有表單域「值」,你沒有關閉表單。此外,沒有$電池 以下解決方案適用於我

<p><b>Billing Information</b></p> 
    <form action="" method="get"> 

     <p>Name: 
    <input type="text" name="firstname"> 
    <br> 
     <strong>Items:</strong></p> 
    </form> 
    <form id="form1" method="post" action=""> 
     <p> 
     <input type="checkbox" name="one" value= "2.39"/> 
     <label for="one">Four 100-watt light bulbs for $2.39</label> 
     <p> 
    <input type="checkbox" name="two" value= "4.29"/> 
    <label for="two">Eight 100-watt light bulbs for $4.29</label> 
    <p> 
     <input type="checkbox" name="three" value= "3.95"/> 
    <label for="three">Four 100-watt long-life light bulbs for $3.95</label> 
     </p> 
     <p> 
     <input type="checkbox" name="four" value= "7.49"/> 
    <label for="four">Eight 100-watt long-life light bulbs for $7.49</label> 
    </p> 


      <input name="battery" name = "battery" type="number" id="battery" size="1" maxlength="3" /> 
<label for="battery">Battery Packs Checkbox $10.42 each:</label> 

    <input type ="submit" name="value" /> 

</form> 
     <p><strong><b>Card Details</b>:</strong></p> 



<p> 

    <?php 
    if(isset($_POST['value'])) 
    { 
     $one = $_POST['one']; 
     $two = $_POST['two']; 
     $three = $_POST['three']; 
     $four = $_POST['four']; 
     $five = $_POST['battery']; 

    $total = $one + $two + $three + $four + $five; 

    $interest = $total * 0.175; 
    echo "Total cost is " .$total; 
    } 


    ?> 

    </p> 

編輯:我不知道,如果你在一個單獨的形式需要「名稱」。雖然我可能是錯的。編輯:你已經在你的問題中改變了你的代碼。不確定這個答案是否適用。