Basically this is a pretty straight forward application. The values are all best on a set of conditional statements held in a function and when the user presses submit, it SHOULD calculate the form....However, this is not the case, for some reason it keeps returning 0. I have tried and tried and tried....to no avail. I have attached the files so you can sort through a little easier as there are a good amount of lines.
Thanks!
EDIT: Here is the code.
index.php - HTML for the user form (not styled, just the framework)
<? require('functions.php'); ?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="ezShipForm">
<!-- Begin Business & Contact Info --->
<input name="company" type="text" placeholder="Company"><br>
<input name="address" type="text" placeholder="Address"><br>
<input name="city" type="text" placeholder="City"><br>
<select name="state">
<option value="0">State</option>
<?php echo generateStateOptions($stateList); ?>
</select><br>
<input name="zipcode" type="text" placeholder="Zip Code"><br>
<input name="contactPhone" type="text" placeholder="Contact Phone"><br>
<input name="contactFax" type="text" placeholder="Contact Fax"><br>
<input name="contactName" type="text" placeholder="Contact Name"><br>
<input name="contactEmail" type="text" placeholder="Contact E-mail"><br>
<!-- End Business & Contact Info --->
<!-- Begin Calculations --->
<input name="fuelPrice" type="text" placeholder="Today's Fuel Rate">
http://www.eia.gov/oog/info/wohdp/diesel.asp<br>
<select name="trailerType">
<option value="Flat Bed">Flatbed</option>
<option value="Step Deck">Step Deck</option>
<option value="Van">Van</option>
<option value="Refer">Refer</option>
<option value="RGN/Lo-Boy">RGN/Lo-Boy</option>
</select> <br>
<input name="pickUpDate" type="text" placeholder="MM/DD/YYYY"><br>
<input name="startingCity" type="text" placeholder="Starting City"><br>
<select name="startingState">
<option value="0">State</option>
<?php echo generateStateOptions($stateList); ?>
</select><br>
<input name="destinationCity" type="text" placeholder="Destination City"><br>
<select name="destinationState">
<option value="0">State</option>
<?php echo generateStateOptions($stateList); ?>
</select><br>
<input name="loadedMiles" type="text" placeholder="Loaded Miles">http://www.truckmiles.com/<br>
<select name="loadType">
<option value="Full">Full</option>
<option value="Partial">Partial</option>
</select><br>
<select name="loadSize">
<option value="Yes">Oversized</option>
<option value="No">Not Oversized</option>
</select><br>
<input name="loadLength" type="text" placeholder="Load Length">Ex: 120in = 10ft<br>
<input name="loadWeight" type="text" placeholder="Weight">Ex: 10500lbs = 10.5<br>
<input name="loadWidth" type="text" placeholder="Load Width">in inches<br>
<input name="loadHeight" type="text" placeholder="Load Height">in inches<br>
<select name="tarped">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select><br>
<select name="twicCardReq">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select><br>
<input name="permits" type="text" value="0">If yes, How many states?<br>
<input name="pilotCars" type="text" value="0">If yes, How many?<br>
<input name="loadDescription" type="text" placeholder="Brief Load or Product Description"><br>
<input name="comments" type="text" placeholder="Other Comments"><br>
<input name="total" type="text"><br>
<input name="submit" type="submit" value="Submit">
<input name="overWidth102" type="hidden">
<input name="overWidth120" type="hidden">
<input name="overWidth144" type="hidden">
<input name="overWidth168" type="hidden">
<input name="overLength52" type="hidden">
<input name="overLength56" type="hidden">
<input name="overLength58" type="hidden">
<input name="overLength60" type="hidden">
<input name="overLength62" type="hidden">
</form>
<?php
if (isset($_POST['submit']))
{
//Call the 'performCalculation' Function To Get Total Coat
performCalculation();
}
?>
</body>
</html>
functions.php
<?php
function performCalculation()
{
//Declare User Form Variables
$company = $_POST['company'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$contactPhone = $_POST['contactPhone'];
$contactFax = $_POST['contactFax'];
$contactName = $_POST['contactName'];
$contactEmail = $_POST['contactEmail'];
$fuelPrice = $_POST['fuelPrice'];
$trailerType = $_POST['trailerType'];
$pickUpDate = $_POST['pickUpDate'];
$startingCity = $_POST['startingCity'];
$startingState = $_POST['startingState'];
$destinationCity = $_POST['destinationCity'];
$destinationState = $_POST['destinationState'];
$loadedMiles = $_POST['loadedMiles'];
$loadType = $_POST['loadType'];
$loadSize = $_POST['loadSize'];
$loadLength = $_POST['loadLength'];
$loadWeight = $_POST['loadWeight'];
$loadWidth = $_POST['loadWidth'];
$loadHeight = $_POST['loadHeight'];
$tarped = $_POST['tarped'];
$twicCardReq = $_POST['twicCardReq'];
$permits = $_POST['permits'];
$pilotCars = $_POST['pilotCars'];
$loadDescription = $_POST['loadDescription'];
$comments = $_POST['comments'];
$overWidth102 = $_POST['overWidth102'];
$overWidth120 = $_POST['overWidth120'];
$overWidth144 = $_POST['overWidth144'];
$overWidth168 = $_POST['overWidth168'];
$overLength52 = $_POST['overLength52'];
$overLength56 = $_POST['overLength56'];
$overLength58 = $_POST['overLength58'];
$overLength60 = $_POST['overLength60'];
$overLength62 = $_POST['overLength62'];
$total = $_POST['total'];
//Declare Calculation Variables
$mainRate = ($fuelPrice * 0.166 + 1.06) * 1.25;
$mileRate = $loadedMiles * $mainRate;
$permitRate = $permits * 50;
$pilotCarRate = ($pilotCars * 1.25 * $loadedMiles);
$flatBedRate = $subTotal;
$overSizeRate = $overWidth102 + $overWidth120 + $overWidth144 +
$overWidth168 + $overLength52 + $overLength56 +
$overLength58 + $overLength60 + $overLength62;
//Surcharge Calculation
if ($loadedMiles < 500) {
$surcharge = (500 - $loadedMiles) * .25 * $mainRate;
}
//Load Rate Calculation
if ($loadLength > $loadWeight) {
$loadRate = $loadLength * $loadedMiles * ($mainRate / 34);
} else {
$loadRate = $loadWeight * $loadedMiles * ($mainRate / 34);
}
//Tarped Rate Calculation
if ($tarped == "Yes") {
$tarpRate = 100;
} else {
$tarpRate = 0;
}
//Sub Total Calculation
if ($loadSize == "Full") {
$subTotal = $loadedmiles + $surcharge + $tarpRate + $permitRate + $pilotCarRate;
} else {
$subTotal = $surcharge + $loadRate + $tarpRate + $permitRate;
}
//Step Deck Rate Calculation
if ($trailerType == "Step Deck") {
$trailerRate = $subTotal * .02;
}
//Van Rate Calculation
if ($trailerType == "Van") {
$trailerRate = $subTotal * .02;
}
//Refer Rate Calculation
if ($trailerType == "Refer") {
$trailerRate = $subTotal * .04;
}
//RGN/Lo-Boy Rate Calculation
if ($trailerType == "RGN/Lo-Boy") {
$trailerRate = $subTotal * .10;
}
//Over Width Rate Calculations
if ($loadWidth > 102) {
$overWidthRate = $loadedMiles * .2;
}
if ($loadWidth > 120) {
$overWidthRate = $loadedMiles * .1;
}
if ($loadWidth > 144) {
$overWidthRate = $loadedMiles * .1;
}
if ($loadWidth > 168) {
$overWidthRate = $loadedMiles * .1;
}
//Over Length Rate Calculations
if ($loadLength > 52) {
$overWidthRate = $loadedMiles * .14;
}
if ($loadLength > 56) {
$overWidthRate = $loadedMiles * .07;
}
if ($loadLength > 58) {
$overWidthRate = $loadedMiles * .07;
}
if ($loadLength > 60) {
$overWidthRate = $loadedMiles * .07;
}
if ($loadLength > 62) {
$overWidthRate = $loadedMiles * .07;
}
// Total Rate Calculation
if ($loadedMiles !== 0) {
$total = $trailerRate + $overSizeRate;
echo $total;
} else {
$total = 0;
}
}
//Generate List of States
$stateList = array ('alabama'=>"AL",
'Alaska'=>"AK",
'Arizona'=>"AZ",
'Arkansas'=>"AR",
'California'=>"CA",
'Colorado'=>"CO",
'Connecticut'=>"CT",
'Delaware'=>"DE",
'District Of Columbia'=>"DC",
'Florida'=>"FL",
'Georgia'=>"GA",
'Hawaii'=>"HI",
'Idaho'=>"ID",
'Illinois'=>"IL",
'Indiana'=>"IN",
'Iowa'=>"IA",
'Kansas'=>"KS",
'Kentucky'=>"KY",
'Louisiana'=>"LA",
'Maine'=>"ME",
'Maryland'=>"MD",
'Massachusetts'=>"MA",
'Michigan'=>"MI",
'Minnesota'=>"MN",
'Mississippi'=>"MS",
'Missouri'=>"MO",
'Montana'=>"MT",
'Nebraska'=>"NE",
'Nevada'=>"NV",
'New Hampshire'=>"NH",
'New Jersey'=>"NJ",
'New Mexico'=>"NM",
'New York'=>"NY",
'North Carolina'=>"NC",
'North Dakota'=>"ND",
'Ohio'=>"OH",
'Oklahoma'=>"OK",
'Oregon'=>"OR",
'Pennsylvania'=>"PA",
'Rhode Island'=>"RI",
'South Carolina'=>"SC",
'South Dakota'=>"SD",
'Tennessee'=>"TN",
'Texas'=>"TX",
'Utah'=>"UT",
'Vermont'=>"VT",
'Virginia'=>"VA",
'Washington'=>"WA",
'West Virginia'=>"WV",
'Wisconsin'=>"WI",
'Wyoming'=>"WY");
//Generate State Options for User Forms
function generateStateOptions($array)
{
$string = '';
foreach($array as $k => $v)
{
$string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n";
}
return $string;
}
//End of file
?>