Learning php - Help with superglobals
Posted: Thu Aug 05, 2010 5:43 pm
This is just a script from the book so im not looking for help with the code persay but rather i seem to be having a hard time if i dont use superglobals to retrieve information from the forms...... anything im missing? im running apache with php5 local
so for example this code executes correctly
if (isset($_GET['source'])) {
if (is_numeric($_POST['quantity'])) {
$_POST['total'] = (($_POST['quantity']) * ($_POST['price'])) * ($taxrate + 1);
but this one dosent
if (isset($source)) {
if (is_numeric($quantity)) {
$total = ($quantity * $price) * ($taxrate + 1);
so for example this code executes correctly
if (isset($_GET['source'])) {
if (is_numeric($_POST['quantity'])) {
$_POST['total'] = (($_POST['quantity']) * ($_POST['price'])) * ($taxrate + 1);
but this one dosent
if (isset($source)) {
if (is_numeric($quantity)) {
$total = ($quantity * $price) * ($taxrate + 1);
Code: Select all
<?php
function calculate_total($quantity, $price, $taxrate) {
$total = ($quantity * $price) * ($taxrate + 1);
$total = number_format ($total, 2);
echo 'You are purchasing $quantity widget(S) at a cost of \$$price each for a total of \$$total \n' ;
}
if (isset($_GET['source'])) {
if (is_numeric($_POST['quantity'])) {
$_POST['total'] = (($_POST['quantity']) * ($_POST['price'])) * ($taxrate + 1);
$_POST['total'] = number_format (($_POST['total']), 2);
echo "You are purchasing {$_POST['quantity']} widget(S) at a cost of \${$_POST['price']} each for a total of \${$_POST['total']} \n" ;
} else {
echo 'Please enter a valid quantity for purchase';
}
} else {
echo 'you have accessed this page inappropriately';
}
?>