2013-03-17 123 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> 

编辑:我不知道,如果你在一个单独的形式需要“名称”。虽然我可能是错的。编辑:你已经在你的问题中改变了你的代码。不确定这个答案是否适用。