开发者

PHP Calculator Problem

I'm trying to create a calculator where the user can put in 4 values, these then each multiply by 0.75 and then get added together to give a price in pounds.

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

-----------My PHP:----------

Results

<?
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);

?>

I'm a bit of a novice and it's not working - can you help? Cheers开发者_StackOverflow社区, Steph


$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";

You have syntax problems in your code. Also do not rely on register_globals, always use superglobals to read data from user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜