For school I’m supposed to check this php file for errors, everyone else in the class already checked the file for errors and fixed at least one error. The file contains and if, else-if, else statement that validates the html form located within the php file. For the life of me I cannot figure out why it won’t pass the validation. Any help would be greatly appreciated. I will be zipping and attaching my files to this post. Actually I will also include the php code below.
[php]<?php # Chapters 9-11 Discussion Question - Debugging
$page_title = ‘Driving to Canada’;
include (‘includes/header.html’); // Relative link read “.php” instead of “.html”
// Tests to see if the form has been submitted before code is executed. This is used when the form and the
// form processing are contained together within one .php file rather than separate .html file.
// There is NO error on the following line:
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
// Retrieve the values from the form:
$city = $_POST['city'];
$distance = $_POST['distance'];
$gallon_price = $_POST['gallon_price'];
$efficiency = $_POST['efficient'];
// Form validation:
if ( empty($city) OR empty($distance) OR empty($gallon_price) OR empty($efficient) )
{
print("<span class='error'>ERROR: Input is missing!</span>");
}
elseif ( !is_numeric($distance) OR !is_numeric($gallon_price) )
{
print("<span class='error'>ERROR: Non-numeric input found!</span>");
}
else {
// Calculate the results:
$gallons = $distance/$efficiency;
$dollars = $gallons * $gallon_price;
$hours = $distance/60;
// Print the results:
print("<h1>Total Estimated Cost</h1>");
print("<p>The distance from $city to Winnipeg, Manitoba, is $distance miles. The total cost of driving to Winnipeg, averaging $efficiency miles per gallon, and paying an average of $number_format($gallon_price, 2) per gallon, is $".number_format($dollars, 2).". If I drive at an average of 60 miles per hour, the trip will take approximately ".number_format($hours, 2)." hours.</p>");
}
} // End of main submission IF.
// Leave the PHP section and create the HTML form:
?>
Trip to Canada
Starting City:
Distance (in miles) to Winnipeg, Manitoba:
Average Price Per Gallon: 2.89 3.09 3.34
Fuel Efficiency: Terrible Decent Very Good Outstanding
<?php include ("includes/footer.html"); ?>[/php]phpproblem.zip (2.54 KB)