[PHP-DB] Newby variable error

2004-09-15 Thread W Roothman
Wizards,

I am VERY new to PHP, paging through Meloni's 'PHP Essentials' I get the following 
error which I assume is very simple to solve, but for me. I have tried different 
approaches in identifying the 'price' variable with no luck:

error:

Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php 
on line 20

Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php 
on line 24

You ordered 1 bags of Ethopian Harrar.

Bags of Ethopian Harrar are R0.00 each.

Your subtotal is R0.00.

Sales tax is 14% in this location.

R0.00 has been added to your order.

You owe R0.00 for your coffee.

code:

show_calculate_b.php

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN
HTML
HEAD
TITLEBean Counter Form/TITLE
/HEAD
BODY
FORM method=POST action=do_calculate.php
PSelect a bean type:/P
SELECT name=beans size=1
 OPTION value=Ethiopian HarrarEthiopian Harrar - $14.25/OPTION
 OPTION value=KonaKona - $16.25/OPTION
 OPTION value=SumatraSumatra - $13.00/OPTION
/SELECT
PHow many bags would you like?/P
SELECT name=quantity size=1
 OPTION value=11/OPTION
 OPTION value=22/OPTION
 OPTION value=33/OPTION
 OPTION value=44/OPTION
 OPTION value=55/OPTION
/SELECT
INPUT type=submit value=Submit
/FORM
/BODY
/HTML

do_calculate_b.php

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN
HTML
HEAD
TITLEBean Counter Results/TITLE
/HEAD
BODY
?php
// set up the pricing assignments
if ($_POST[beans] == Ethiopian Harrar) {
 $price = 14.25;
} else if ($_POST[beans] == Kona) {
 $price = 16.25;
} else if ($_POST[beans] == Sumatra) {
 $price = 13.00;
}
$sales_tax = .0825;
$sub_total = $price * $_POST[quantity];
$sales_tax_amount = $sub_total * $sales_tax;
$sales_tax_pct = $sales_tax * 100;
$grand_total = $sub_total + $sales_tax_amount;
$fmt_price = sprintf(%0.2f,$price);
$fmt_sub_total = sprintf(%0.2f,$sub_total);
$fmt_sales_tax_amount = sprintf(%0.2f,$sales_tax_amount);
$fmt_grand_total = sprintf(%0.2f,$grand_total);
echo PYou ordered $_POST[quantity] bags of $_POST[beans]./p;
echo PBags of $_POST[beans]  are \$$fmt_price each./p;
echo PYour subtotal is \$$fmt_sub_total./p;
echo PSales tax is $sales_tax_pct% in this location./p;
echo P\$$fmt_sales_tax_amount has been added to your order./p;
echo PYou owe \$$fmt_grand_total for your coffee./p;
?
/BODY
/HTML

Regards and many thanks,

Will

Re: [PHP-DB] Newby variable error

2004-09-15 Thread graeme
Hi,
first step in debugging...learn to love the var_dump() function :)
just add the following code to the do_calculate.php function
...
?php
var_dump ($_POST);
echo br;
// set up the pricing assignments
...
This will display what is held in your $_POST variable. When you run the 
script at the start of your output will be the following

array(2) { [beans]= string(16) Ethiopian Harrar [quantity]= 
string(1) 3 }

Notice that beans and quantity are in double quotes.
From now it should be east to fix ;)
graeme.
W Roothman wrote:
Wizards,
I am VERY new to PHP, paging through Meloni's 'PHP Essentials' I get the following 
error which I assume is very simple to solve, but for me. I have tried different 
approaches in identifying the 'price' variable with no luck:
error:
Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php 
on line 20
Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php 
on line 24
 

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php