...

View Full Version : unexpected $end??



likon
07-27-2007, 06:39 AM
hi guys. I have been using dreamweaver to edit php
this script actually I got it directly from book.
I was wondering why it always says unexpected $end at the end of the script


<?php
$page_title='Calculator';
//define function calculate total...
function calculate_total($qty, $cost, $tax) {
$taxrate=$tax/100;
$total=($qty*$cost)*($taxrate+1);
echo '<p> The total cost of purchasing '.$qty.' widget(s) at $'.number_format($cost,2).'each, including a tax rate of '.$tax.'% is $'.number_format($total,2).'</p>';
//form validation...
if(isset($_POST['submitted'])){
if(is_numeric($_POST['quantity'],$_POST['price'],$_POST['tax'])){ // this is not like book, maybe works tho
//print the heading...
echo '<h1> Total Cost</h1>';
calculate_total($_POST['quantity'],$_POST['price'],$_POST['tax']);
echo '<p><br/></p>';
} else {
echo '<font size=3>Error!</font> <p> Please enter a valid quantity, price and tax</p>';
}
}
//end of form validation
// leave php and go to html form...
?>

<h2>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 if(isset($_POST['tax']))echo $_POST['tax]; ?>"/></p>
<p><input type="submit" name="submit" value="Calculate!"/></p>
<p><input type="hidden" name="submitted" value="TRUE"/></p>
</form>
NOTE: it always error at the end
I deleted some stuff like <html> < head> which have not much effect on script CMIIW

PappaJohn
07-27-2007, 07:34 AM
1. You never close the function


//define function calculate total...
function calculate_total($qty, $cost, $tax) {
$taxrate=$tax/100;
$total=($qty*$cost)*($taxrate+1);
echo '<p> The total cost of purchasing '.$qty.' widget(s) at $'.number_format($cost,2).'each, including a tax rate of '.$tax.'% is $'.number_format($total,2).'</p>';
//form validation...

a better way:


//define function calculate total...
function calculate_total($qty, $cost, $tax) {
$taxrate=$tax/100;
$total=($qty*$cost)*($taxrate+1);
return '<p> The total cost of purchasing '.$qty.' widget(s) at $'.number_format($cost,2).'each, including a tax rate of '.$tax.'% is $'.number_format($total,2).'</p>';
}
//form validation...

Then change


calculate_total($_POST['quantity'],$_POST['price'],$_POST['tax']);

to


echo calculate_total($_POST['quantity'],$_POST['price'],$_POST['tax']);


2.


if(is_numeric($_POST['quantity'],$_POST['price'],$_POST['tax'])){ // this is not like book, maybe works tho

no it won't work. should be


if(is_numeric($_POST['quantity']) && is_numeric($_POST['price']) && is_numeric($_POST['tax'])){ // this is not like book, maybe works tho


3.


I deleted some stuff like <html> < head> which have not much effect on script

not a good idea.

There may be other problems, that was just a quick look.

likon
07-27-2007, 04:40 PM
oh ? I never close the functioN ?
I have no clue why it is....
cause the I typed directly from the book and it won't work... it's a
"PHP and mysql , for dynamic websites second edition " by larry ulman

_Aerospace_Eng_
07-27-2007, 05:15 PM
You are also missing a quote here

<p>Tax:<input type="text" name="tax" size="5" maxlength="10" value="<?php if(isset($_POST['tax']))echo $_POST['tax']; ?>"/></p>

likon
07-27-2007, 06:09 PM
oh thanks ..
but when I run this script , it also says

if(isset($_POST['submitted'])){
if(is_numeric($_POST['quantity'])$$is_numberic($_POST['price'])&&is_numberic($_POST['tax'])){ Dont' bother looking back to the first script I posted. cause this one is little modified.


unexpected end....
this script makes me pain ...

_Aerospace_Eng_
07-27-2007, 06:12 PM
if(isset($_POST['submitted'])){
if(is_numeric($_POST['quantity']) && is_numberic($_POST['price']) && is_numberic($_POST['tax'])){
You used $$ not && in that snippet. I suggest you pay more attention to what you are typing. These are simple mistakes that shouldn't be happening.

rafiki
07-27-2007, 06:17 PM
if(isset($_POST['submitted'])){
if(is_numeric($_POST['quantity']) && is_numberic($_POST['price']) && is_numberic($_POST['tax'])){
You used $$ not && in that snippet. I suggest you pay more attention to what you are typing. These are simple mistakes that shouldn't be happening.

aswell as is_numberic isnt a function
i think you mean is_numeric
(lol i know you got it right apart from this time)

likon
07-27-2007, 06:20 PM
oh dude.. my bad!..what a damn *** of me Thank you I need to really careful now!!! argh that's why it doesnt work



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum