Having trouble with Functions
Posted: Tue Oct 18, 2011 1:25 pm
Trying to get my program to calculate shipping on an item and i need to have my calculations in a function.
Here's what i have, everything prints out except the shipping,
Here's what i have, everything prints out except the shipping,
Code: Select all
<?php
// Input Data From Form
$Cost = $_POST['fielda'];
//Calculate tax
$Tax = ($Cost * .06);
$Ship = 0;
//Set Current Date & Shipping Date (15 days)
$Date = date('l, F d, Y');
$ShipDate = date('F d, Y',strtotime('+ 15 days'));
//Calculate Shipping
function shipping_cost($Cost) {
if ($Cost > 0 && $Cost <= 25.00 ){
$Ship = 3.00; }
if ($Cost >= 25.01 && $Cost <= 50.00 ){
$Ship = 4.00;}
if ($Cost >= 50.01 && $Cost <= 75.00) {
$Ship = 5.00;}
if ($Cost > 75.00) {
$Ship = 6.00;}
return $Ship; }
//Calculate Order Total
$Total = ($Cost + $Tax + $Ship);
$Cost2 = number_format($Cost,2);
$Tax2 = number_format($Tax,2);
$Ship2 = number_format($Ship,2);
$Total2 = number_format($Total,2);
print "Date: $Date<br><br>";
print "Cost: $$Cost2<br><br>";
print "Tax: $$Tax2<br><br>";
print "Ship: $$Ship2<br><br>";
print "Total: $$Total2<br><br>";
print "Estimated Ship Date is $ShipDate<br> " ;
?>