Please help

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

Post Reply
Ken
Forum Newbie
Posts: 1
Joined: Wed Mar 05, 2003 1:11 pm

Please help

Post by Ken »

I'm a beginner of PHP, I downloaded the newest verion of php from php.net. I started to try some tutorials like this:

<?php
$Cost = 2000.00;
$Tax = 0.06;
if($_GET[Quantity]) {
$Quantity = abs($_GET[Quantity]);
$Discount = abs($_GET[Discount]);
$Tax++;
$TotalCost = (($Cost * $Quantity) - $Discount) * $Tax;
$Payments = (round($TotalCost, 2) / 12);
//Print the results.
print("You requested to purchase $Quantity widget(s) at \$$Cost each.\n<p>");
print ("The total with tax, minus your \$$Discount, coumes to $");
printf("%01.2f", $TotalCost);
print(".\n<p>You may purchase the widgets(s) in 12 monthly installments of $");
printf("%01.2f", $Payments);
print("each. \n<p>");
}
?>

After ran the page, there couples of craps came up like:

Notice: Use of undefined constant Quantity - assumed 'Quantity' in Calculate.php on line 11

Notice: Undefined index: Quantity in Calculate.php on line 11

Anybody know how to solve it? And also please tell me where I can the up-to-date tutorials of PHP, cause I followed some of the examples from other web sites and there are not work. Just like the tutorials told me to use $Quantity to receive the passed value. But I found that the correct one is $_GET[Quantity]. So please help. Thanks everyone.
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

for security register_globals was switched off in recent builds of PHP

makes for better scripting :)

Your only prob with your script is non encasing the variable names in quotes - eg $_GET['quantity']; <-- with single quotes
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have a read of the 'Array do's and don'ts' section on this page:
http://www.php.net/manual/en/language.types.array.php

Mac
Post Reply