parse error
Posted: Sat May 16, 2009 1:40 pm
Hi all. Im new to learning PHP, and it is my first real attempt at scripting/coding, other than basic HTML and CSS. I hope this is the right place to ask this question. I am following a tutorial script and I have a parse error on line 26, but I just cannot for the life of me see what the problem is. At this point Im so tempted to get frustrated and quit but I dont want to. Can anyone please help me see what the parse error is (the parse error is on line 26 which counting down means it is on or abouts the line with the echo statement to print the error "please enter a valid quantity, price, and tax." I hope I have been clear about my query: -
Code: Select all
<?php # script 3.5 - calculator.php
$page_title = 'Widget Cost Calculator';
if (isset($_POST['submitted'])) {
if ( is_numeric($_POST['quantity']) && is_numeric($_POST['price']) && is_numeric($_POST['tax']) ) {
$total = ($_POST['quantity'] * $_POST['price']);
$taxrate = ($_POST['tax'] / 100);
$total += ($total * $taxrate);
echo '<h1>Total Cost</h1>
<p>The total cost of purchasing ' . $_POST['quantity'] . ' widget(s) at $' . number_format ($_POST['price'], 2) . '
each, including a tax rate of ' . $_POST['tax'] . '%, is $' . number_format ($total, 2) , '.</p>;
} else {
echo '<h1>error!</h1> <p>please enter a valid quantity, price, and tax.</p>';
}
}
?>
<h1> Widget Cost Caluclator</h1>
<form action="calculator.php" method="post">
<p>Quantity: <input type="text" name="quantity" size="5" /> </p>
<p>Price: <input type="text" name="price" size="5" /></p>
<p>Tax (%): <input type="text" name="tax" size="5" /></p>
<p><input type="submit" name="submit" value="calculate!" /></p>
<input type="hidden" name="submitted" value="1" />
</form>