PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hobden81
Forum Newbie
Posts: 1 Joined: Sat May 16, 2009 1:31 pm
Post
by hobden81 » 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>
Last edited by
Benjamin on Sat May 16, 2009 2:12 pm, edited 1 time in total.
Reason: Added [code=php] tags.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat May 16, 2009 2:15 pm
Use
Code: Select all
tags when posting code in the forums. Syntax highlighting has revealed the problem
Moved to PHP - Code
Darhazer
DevNet Resident
Posts: 1011 Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria
Post
by Darhazer » Sat May 16, 2009 2:22 pm
in the posted code, at line 21 there should be a ' before the ;
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>