Help with some basic code
Posted: Mon Feb 04, 2008 4:10 pm
Hi,
I apologize if my use of the forums tags is improper I am incredibly new to all web programming and so may have got it wrong.
I was just wondering if anybody could help me with my code which is returning the error below. The code is supposed to create a simple calculator to format quantity, price and tax into a grand total.
Any help given would be greatly appreciated.
Many thanks
Tom
I apologize if my use of the forums tags is improper I am incredibly new to all web programming and so may have got it wrong.
I was just wondering if anybody could help me with my code which is returning the error below. The code is supposed to create a simple calculator to format quantity, price and tax into a grand total.
Any help given would be greatly appreciated.
Many thanks
Tom
Code: Select all
<?php # Script 3.5 - calculator.php
$page_title = 'Widget Cost Calculator';
function calculate_total ($qty, $cost, $tax = 17.5) {
$taxrate = $tax / 100; // Turn 17.5% into .175.
$total = ($qty * $cost) * ($taxrate + 1);
return number_format ($total, 2)
}
if (isset($_POST['submitted'])) {
if (is_numeric($_POST['quantity']) &&
is_numeric($_POST['price'])) {
echo '<h1 id="mainhead">Total Cost</h1>';
if (is_numeric($_POST['tax'])) {
$total_cost = calculate_total
($_POST['quantity'], $_POST['price'], $_POST['tax']);
} else {
$total_cost = calculate_total
($_POST['quantity'], $_POST['price']]);
}
echo '<p>The total cost of
purchasing ' . $_POST['quantity']
. ' widget(s) at $' . number_format
($_POST['price'], 2) . 'each is $'
. $total_cost . '.</p>
echo '<p><br /><p>';
} else {
echo '<h1 id="mainhead">Error!</h1>
<p class="error">Please enter a
valid quantity and price.</p><p>
<br /></p>';
}
}
?>
<h2>Widget Cost Calculator</h2>
<form_action="calculator.php"
method="post">
<p>Quantity: <input type="text"
name="quantity" size="5" maxlength="10"
value="<?php if (isset($_POST
['quantity'])) echo $_POST['quantity'];
?>"/></p>
<p>Price: <input type="text"
name="price" size="5" maxlength="10"
value="<?php if (isset($_POST
['price'])) echo $_POST['price'];
?>"/></p>
<p>Tax (%): <input type="text"
name="tax" size="5" maxlength="10"
value="<?php is (isset($_POST
['tax']; ?>" /></p>
<p><input type="submit" name="submit"
value="Calculate!"/></p>
<input type="hidden" name="submitted"
value="TRUE" />
</form>
<?php
Code: Select all
Parse error: syntax error, unexpected '}' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\calculator.php on line 17