-1

我有表单和 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 的东西不是很好。请帮我!

4

1 回答 1

1

没有表单字段“值”,您没有关闭表单。此外,没有 $battery 以下解决方案适用于我

   <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>

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

于 2013-03-17T16:18:58.483 回答