Jump to content
Larry Ullman's Book Forums

cmgr

Members
  • Posts

    2
  • Joined

  • Last visited

cmgr's Achievements

Newbie

Newbie (1/14)

  • Week One Done Rare
  • One Month Later Rare
  • One Year In Rare

Recent Badges

0

Reputation

  1. I changed the isset line and removed the commas, replaced them with && and included the whole isset() block in a paraenthesis set,. I removed the placeholder code in the html form. The page now loads, but it is now only displaying the else clause, so it's still not working correctly.
  2. I am trying to do your tutorials and getting an HTTP 500 error. It is coming from this script. it is showing me errors in the php block (not the HTML) in Dreamweaver. It is coming from the isset() and the else lines. Do you see an error? The html will work without it. It is currently part of another page, and the rest of it is fine. I have tried to type it as it was shown in the book, although I tried a few other versions, but still got the same result. Should this use $_GET[] instead? <?php // Check for form submission if($_SERVER['REQUEST_METHOD'] == 'POST') { //Minimal form validation: if (isset $_POST['distance'], $_POST['gallon_price'], $_POST['efficiency']) && is_numeric($_POST['distance']) && is_numeric($_POST['gallon_price']) && is_numeric($_POST['efficiency']) { // Calculate the results $gallons = $_POST['distance'] / $_POST['efficiency']; $dollars = $gallons * $_POST['gallon-price']; $hours = $_POST['distance']/65; //65 mph //Print results echo '<div class="error"><h2>Total estimated cost</h2></div> <p>The total cost of driving is ' .$_POST['distance']. ' miles, averaging ' .$_POST['efficiency']. 'miles per gallon, and paying an average of $'.$_POST['gallon-price']. 'per gallon, is $'.number_format($dollars, 2). '. If you drive an average of 65 mph, the trip will take approximately '. number_format($hours, 2). 'hours.</p>';} else { //invalid submitted values. echo '<div class="error"><h2>Error</h2><p>Please enter a valid distance, price per gallon, and fuel efficiency.</p></div>'; } } //leave PHP section, create HTML form below. ?> <section class="calculator"> <h2>Trip Cost Calculator</h2> <form action="calculator1.php" method="post"> <p>Distance (in miles). <input type="number" name="distance" placeholder="10"></p> <!-- add required to make it not submit unless it is filled out --> <p>Avg. Price Per Gallon: <input type="radio" name="gallon_price" value="3.00"> 3.00 <input type="radio" name="gallon_price" value="3.50"> 3.50 <input type="radio" name="gallon_price" value="4.00"> 4.00 </p> <p>Fuel Efficiency: <select name="efficiency"> <option value-"10">Terrible</option> <option value-"20">Decent</option> <option value-"30">Very good</option> <option value-"50">Outstanding</option> </select></p> <p><input type="submit" name="submit" value="Calculate!"></p> </form>
×
×
  • Create New...