# 1.4. 下单处理计算总数量，总金额 4 4

``````<?php
// 接收下单物品的数量
\$tireqty = \$_POST['tireqty'];
\$oilqty  = \$_POST['oilqty'];
\$sparkqty= \$_POST['sparkqty'];

// 物品单价，一般不怎么变动，我们先可以用常量定义
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

// 总数量
\$totalqty = 0;

// 总金额
\$totalamount = (float) \$totalqty;

\$totalqty    = \$tireqty + \$oilqty + \$sparkqty;
\$totalamount = \$tireqty * TIREPRICE + \$oilqty * OILPRICE + \$sparkqty * SPARKPRICE;

// 税率
\$taxrate = 0.10;

\$totalamount_tax = \$totalamount * (1 + \$taxrate);
?>

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>下单处理脚本</title>
<body>

<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>

<?php
echo "<p>Order processed at " . date('Y-m-d H:i:s') . "</p>";

echo "<p>Your order is as follows:</p>";
echo "\$tireqty tires<br>";
echo \$oilqty . ' bottles of oil<br>';
echo \$sparkqty . ' spark plugs<br>';

echo "Items ordered : \$totalqty <br/>";
echo "Subtotal: \$" . number_format(\$totalamount, 2) . "<br/>";
echo "Total including tax: \$" . number_format(\$totalamount_tax, 2) . "<br/>";
?>

</body>
</html>``````

``\$totalamount = \$tireqty * TIREPRICE + \$oilqty * OILPRICE + \$sparkqty * SPARKPRICE;``