0

我正在尝试创建一个计算器,用户可以在其中输入 4 个值,然后将每个值乘以 0.75,然后相加得到以英镑为单位的价格。

------------我的HTML:----------

<h2>Monthly Fee &amp; transactions Calculator </h2>
<form action="orderprocessing.php" method=post>
<table>

<tr><td>Total of invoices you send to your customers</td>
<td><INPUT type="text" name="customers" size=10 ></td></tr>

<tr><td>Total of invoices you receive from suppliers </td>
<td><INPUT type="text" name="suppliers" size=10 ></td></tr>

<tr><td>Number of lines on your bank statement</td>
<td><INPUT type="text" name="bank" size=10 ></td></tr>

<tr><td>Number of lines on your credit card statement</td>
<td><INPUT type="text" name="creditcard" size=10 ></td></tr>

<tr><td colspan="2"><INPUT TYPE="submit" name="submit"></td></tr>
</table>
</form>

------------我的PHP:----------

结果

<?
echo "<P>Order Processed.";
echo $customers." Total of invoices you send to your customers<BR>";
echo $suppliers." Total of invoices you receive from suppliers<BR>";
echo $bank." Number of lines on your bank statement<BR>";
echo $creditcard." Number of lines on your credit card statement<BR>";

$totalqty = 0;
$totalamount = 0.00;

define("PRICE", 0.75);

$totalqty = $customers + $suppliers + $bank + $creditcard;

$totalamount = $customers * PRICE
                        + $suppliers * PRICE
                        + $bank * PRICE
      + $creditcard * PRICE;

$totalamount = number_format($totalamount, 2);

echo "<BR>\n";
echo "Items ordered:                 ".$totalqty."<br>\n;
echo "Subtotal:                         ".$totalamount."<BR>"\n;
$totalamount = number_format($totalamount, 2);

?>

我有点新手,但它不起作用 - 你能帮忙吗?干杯,斯蒂芬

4

1 回答 1

2
$customers = $_POST['customers'];
$suppliers = $_POST['suppliers'];
$bank = $_POST['bank'];
$creditcard = $_POST['creditcard'];

$totalqty = 0;
$totalamount = 0.00;

define("PRICE", 0.75);

$totalqty = $customers + $suppliers + $bank + $creditcard;
$totalamount = $totalqty * PRICE;

$totalamount = number_format($totalamount, 2);

echo "<BR>\n";
echo "Items ordered: $totalqty<br>\n";
echo "Subtotal: $totalamount<BR>\n";

您的代码中有语法问题。也不要依赖 register_globals,总是使用超全局变量从用户那里读取数据。

于 2010-02-10T11:37:28.337 回答