无法将信息从html表单发布到php脚本。(未定义索引)

无法将信息从html表单发布到php脚本。(未定义索引),php,html,forms,Php,Html,Forms,我正在开发一个PHP类应用程序,我们必须创建一个在线订购比萨饼的应用程序。我被困在一个html表单上,它没有在脚本上发布,我无法让它工作。我得到以下错误,我不知道如何修复它 我正在开发一个PHP类应用程序,我们必须创建一个在线订购比萨饼的应用程序。我被困在一个html表单上,它没有在脚本上发布,我无法让它工作。我得到以下错误,我不知道如何修复它 HTML索引 <!DOCTYPE html> <html lang="en"> <head> <meta

我正在开发一个PHP类应用程序,我们必须创建一个在线订购比萨饼的应用程序。我被困在一个html表单上,它没有在脚本上发布,我无法让它工作。我得到以下错误,我不知道如何修复它

我正在开发一个PHP类应用程序,我们必须创建一个在线订购比萨饼的应用程序。我被困在一个html表单上,它没有在脚本上发布,我无法让它工作。我得到以下错误,我不知道如何修复它

HTML索引

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="style.css">
  <title>HTech Pizza Online Order</title>
</head>

<body>
  <div class="container">
    <form action="receipt.php" method="POST">
      <h2>HTech Pizzeria Online Order</h2>
      <fieldset>
          <legend><b>Customer Information</b></legend>
          Name: <input type="text" require id="customer" name="customer"
          placeholder="Enter Your Name..."><br>
          Phone Number: <input type="text" require id="phoneNumber" name="phoneNumber"
          placeholder="Enter Your Phone Number..."><br>
          Address: <input type="text" require id="address" name="address"
          placeholder="Enter Your Address..."><br>
      </fieldset>
    </form>
  </div> 
  <form action="receipt.php" method="POST">
    <fieldset>
      <legend><b>Order Customization</b></legend>
      <div class="checkbox">
        <b>Size : </b><br><br>

        <input id="radio3" type="radio" name="size" value="Large"><label for="radio3"><span><span></span></span>Large: $10.00</label> <br>

        <input id="radio2" type="radio" name="size" value="Medium"><label for="radio2"><span><span></span></span>Medium: $8.00</label> <br>

        <input id="radio1" type="radio" name="size" value="Small" checked="checked"><label for="radio1"><span><span></span></span>Personal: $6.00</label> 
        <br>
        <br>

        <b>Crust : </b><br><br>

        <input id="radio4" type="radio" name="crust" value="traditional" checked="checked"><label for="radio4"><span><span></span></span>Traditional: $2.00</label><br>

        <input id="radio5" type="radio" name="crust" value="welldone"><label for="radio5"><span><span></span></span>Well Done: $2.00</label><br>

        <input id="radio6" type="radio" name="crust" value="thin"><label for="radio6"><span><span></span></span>Thin: $2.00</label><br><br>
        <hr>
      </div>
      <div class="checkbox"><b>Toppings:</b><br><br>
        <div>  
          <input id="toppingBox1" type="checkbox" name="toppings[]" value="Pepperoni"><label for="toppingBox1"><span></span>Pepperoni</label> 
        </div>
        <div> 
          <input id="toppingBox2" type="checkbox" name="toppings[]" value="Bacon"><label for="toppingBox2"><span></span>Bacon</label>
        </div>

        <div>
          <input id="toppingBox3" type="checkbox" name="toppings[]" value="Chicken"><label for="toppingBox3"><span></span>Chicken</label>
        </div>

        <div>
          <input id="toppingBox4" type="checkbox" name="toppings[]" value="Sausage"><label for="toppingBox4"><span></span>Sausage</label>
        </div>

        <div>
          <input id="toppingBox5" type="checkbox" name="toppings[]" value="Ham"><label for="toppingBox5"><span></span>Ham</label> 
        </div>

        <div>
          <input id="toppingBox6" type="checkbox" name="toppings[]" value="BlackOlives"><label for="toppingBox6"><span></span>Black Olives</label> 
        </div> 

        <div>
          <input id="toppingBox7" type="checkbox" name="toppings[]" value="Parmesan"><label for="toppingBox7"><span></span>Parmesan</label>
        </div>

        <div>
          <input id="toppingBox8" type="checkbox" name="toppings[]" value="Pineapple"><label for="toppingBox8"><span></span>Pineapple</label>
        </div>
      </div>
      <hr>

      <div class="checkbox"><b>Student Discount: 
        </b><br><br>

        <input id="radio7" type="radio" name="studentBol" value="student"><label for="radio7"><span><span></span></span> Student</label> <br>

        <input id="radio8" type="radio"   name="studentBol" value="nonStudent"><label   for="radio8"><span><span></span></span>Non - Student</label><br>
        <br><hr><br>

        <b>Delivery or Pickup:</b> <br><br>

        <input id="radio9" type="radio" name="modePickup" value="Delivery"><label for="radio9"><span><span></span>
        </span>Delivery</label><br>

        <input id="radio0" type="radio" name="modePickup" value="Pickup"><label for="radio0"><span><span></span></span>Store Pickup</label><br>
        <br>


        <b>Boxes Of Pizza:</b><br><br>
        <div class="custom-select">
          <label>
            <select name="noOfPizza">
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
            </select>
          </label>
        </div>
      </div>
      <br>
      <br>

      Additional Instructions:<br><br>
      <label>
        <textarea name="addInstructions" cols="60" rows="10"></textarea>
      </label>
      <br>
      <br>

      <input class="btn btn1" type="submit" name="order" value="Order Now">

    </fieldset>
    <br>
  </form>
</body>
</html>

HTech比萨饼在线订购
HTech比萨店在线订购
客户信息
名称:
电话号码:
地址:
订单定制 大小:

大型:$10.00
中等:8.00美元
个人:6.00美元

外壳:

传统:2.00美元
干得好:$2.00
瘦:$2.00


配料:

意大利 辣味 香肠 培根 鸡 香肠 火腿 黑橄榄 帕尔马干酪 菠萝
学生折扣:

学生
非学生



送货或取货:

交付
商店提货

几盒比萨饼:

1. 2. 3. 4. 5.

附加说明:




PHP脚本

    <?php
if (isset($_POST['order'])) {

  // Check for pizza size 

  switch ($_POST['size']) {

    case "Small":
      $pizzaSizePrice = 6.00;
      break;

    case "Medium":
      $pizzaSizePrice = 8.00;
      break;

    case "Large":
      $pizzaSizePrice = 10.00;
      break;
  }

  // Checking Student Qualification

  if ($_POST['studentBol'] == "student") {
    $studentBol = true;
  } else {
    $studentBol = false;
  }

  // Toppings

  $toppingArray = $_POST['toppings'];

  if (count($toppingArray) == 1) {
    $toppingAmount = 0.00;
  } else {

    // First topping free, added toppings an extra $1

    $toppingAmount = count($toppingArray) - 1;
  }

  // Pickup

  if ($_POST['modePickup'] == "Delivery") {
    $modePickup = 5.00;
  } else {
    $modePickup = 0.00;
  }

  $crustType = 2.00;

  $numberOfPizza = $_POST['noOfPizza'];
  $instructions = $_POST['addInstructions'];

  // Calculating Amount

  $netAmount = $crustType + $pizzaSizePrice + $toppingAmount;

  $netAmount = $netAmount * $numberOfPizza;

  // Adding Delivery Fee

  $netAmount = $netAmount + $modePickup;

  if ($studentBol) {
    $studentDiscount = $netAmount * 10 / 100;

    // Applying the student discount 

    $netAmount = $netAmount - $studentDiscount;

    $studentDiscount = number_format($studentDiscount, 2, '.', '');
  }

  // adding tax

  $salesTax = $netAmount * 10 / 100;
  $salesTax = number_format($salesTax, 2, '.', '');

  $total = $salesTax + $netAmount;
  $total = number_format($total, 2, '.', '');
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="style.css">
  <title>Order Confirmation</title>
</head>

<body>
  <h2>Order Confirmation</h2>

  <hr>

  <h3>Customer Information:</h3>

  <h3>First Name:</h3><?php echo $_POST['customer']; ?>
  <h3>Phone Number:</h3><?php echo $_POST['phoneNumber']; ?>
  <h3>Address:</h3><?php echo $_POST['address']; ?>

  <hr>

  <h3>Size: </h3><?php echo $_POST['size'] . " $" . $pizzaSizePrice; ?>

  <h3>Crust Type: </h3><?php echo $_POST['crust'] . " $2"; ?>

  <h3>Toppings: </h3>
  <?php
  if (count($toppingArray) == 1) {

    foreach ($toppingArray as $topping) {
      echo $topping . " Free<br>";
    }
  } else {
    foreach ($toppingArray as $topping) {
      // First topping free

      if ($topping == "Peperroni") {
        echo $topping . " Free<br>";
      } else {
        echo $topping . " $1<br>";
      }
    }
  }
  ?>


  <h3>Pizza's Ordered: </h3><?php echo $numberOfPizza; ?>

  <h3>Additional Instructions:</h3> <?php echo $_POST['addInstructions']; ?>

  <br>
  <hr>

  <h3>Delivery or Pickup: </h3><?php echo $_POST['modePickup'] . " $" . $modePickup; ?>

  <!-- Check Student Discount -->
  <?php
  if ($studentBol) {
    echo "<br><br>Student Discount: $" . $studentDiscount;
  }
  ?>

  <h3>Sales Tax:</h3> $<?php echo $salesTax; ?>

  <hr>

  <h3>Total Due on Delivery: </h3> $<?php echo $total; ?>

</body>

</html>

订单确认
订单确认

客户信息: 名字: 电话号码: 地址:
尺寸: 地壳类型: 浇头: 比萨饼点了: 其他说明:

交货或提货: 销售税:$
交货时应付总额:$
这是因为HTML中有两个表单

请参阅代码的这一部分:

...
    <form action="receipt.php" method="POST">
      <h2>HTech Pizzeria Online Order</h2>
      <fieldset>
          <legend><b>Customer Information</b></legend>
          Name: <input type="text" require id="customer" name="customer"
          placeholder="Enter Your Name..."><br>
          Phone Number: <input type="text" require id="phoneNumber" name="phoneNumber"
          placeholder="Enter Your Phone Number..."><br>
          Address: <input type="text" require id="address" name="address"
          placeholder="Enter Your Address..."><br>
      </fieldset>
  </div> 
  <form action="receipt.php" method="POST">
...
。。。
HTech比萨店在线订购
客户信息
名称:
电话号码:
地址:
...
您只需提交两个表单中的第二个,客户信息在第一个表单中。试着把你的字段合并成一个表单,你就可以开始了


希望这有帮助。

您有两个
。只使用一个包含所有输入的表单。是的,提交按钮位于第二个表单中,因此仅提交一个表单。