PHP Calc的复选框数量勾选&添加他们的价值+税

时间:2018-03-26 07:08:24

标签: php html if-statement math checkbox

我需要编写一个PHP脚本,在添加17.5%增值税后计算订购灯泡和电池组的总成本。该计划必须告知买方确切地在表中订购了什么,以及选择了哪种信用卡付款。

到目前为止,这是我的代码(这是一个带有复选框和单选按钮的表单,用于订购灯泡

bulbs.html



<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<script>
function formSubmit() {
    document.forms["myForm"].submit();
}
</script>
</head>
<body>

<form name="myForm" action="calc.php" method="post">
Name: <input type="text" name="fullname"><br>

  <input type="checkbox" name="bulb[]" value="Bulb1"> Four 100-watt light bulbs for $2.39<br>
  <input type="checkbox" name="bulb[]" value="Bulb2"> Eight 100-watt light bulbs for $4.29<br>
  <input type="checkbox" name="bulb[]" value="Bulb3"> Four 100-watt long-life light bulbs for $3.95<br>
  <input type="checkbox" name="bulb[]" value="Bulb4"> Eight 100-watt long-life light bulbs for $7.49<br>


Number of battery packs you would like for $10.42 each: <input type="text" name="batterypacks"><br>

  <input type="radio" name="card" value="Card1"> Visa<br>
  <input type="radio" name="card" value="Card2"> Mastercard<br>
  <input type="radio" name="card" value="Card3"> American Express<br>

  <input type="submit" value="Submit">
</form>


</body>
</html>
&#13;
&#13;
&#13;

这是我的 calc.php

&#13;
&#13;
<?php

echo $_POST;

echo "<br>";

echo $_POST['bulb'];




if(isset($_POST['bulb'])){
  if (is_array($_POST['bulb'])) {
    foreach($_POST['bulb'] as $value){
	$bulb1=2.39;
	$bulb2=4.29;
	$bulb3=3.95;
	$bulb4=7.49;
	$totalCost;
      echo $value;
    }
  } else {
    $value = $_POST['bulb'];
    echo $value;
  }
}



$price = 0;

foreach( $_POST['bulb'] as $key => $value ) {
   switch( $value ) {
      case 'Bulb1':
        $price = $price + 2.39;
        break;
      case 'Bulb2':
        $price = $price + 4.29;
        break;
      case 'Bulb3':
        $price = $price + 3.95;
        break;  
      case 'Bulb4':
        $price = $price + 7.49;
        break;
      
}
echo $price; // Total price

$afterTax = 0;

$price * .175 = $afterTax;

echo $afterTax;



$name = $_GET['card'];


foreach ($name as $card){ 
    echo $card."<br />";
}



?>

// if bulb 1 is selcted, add to total price
//compare checkedItem==Bulb1

else
checkedItem==Bulb2

else
checkedItem==Bulb3
&#13;
&#13;
&#13;

我觉得我真的很亲密!但是,每当我点击&#34;提交&#34;在 bulbs.html 上,它只是引导我访问 calc.php 的代码,并且根本不显示任何值。在计算复选框和添加税方面我缺少什么?

0 个答案:

没有答案