0

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, Steph

2
  • Perhaps you can clarify as to which part isn't working. Commented Feb 10, 2010 at 11:33
  • Also, you could use $totalamount = number_format($totalqty*PRICE, 2); to simplify code a bit. Commented Feb 10, 2010 at 11:45

1 Answer 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";

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.