Question: Problem is from PHP Programming with MySQL Second Edition, Chapter, Exercise 4-5. The goal is two write a all-in-one sticky form that solves the two
Problem is from "PHP Programming with MySQL" Second Edition, Chapter, Exercise 4-5. The goal is two write a all-in-one sticky form that solves the "two trains are moving toward each other" word problem. My code validates but the form doesn't display. Any help would be appreciated. See code below.
0) { echo "Please re-enter the form information below.
"; displayForm($SpeedA, $SpeedB, $Distance); } else $DistanceA = round((($SpeedA/$SpeedB) * $Distance)/(1 + ($SpeedA/$SpeedB)),2); $DistanceB = round($Distance - $DistanceA,2); $TimeA = round($DistanceA/$SpeedA,2); $TimeB = round($DistanceB/$SpeedB,2); echo "Train A traveled $DistanceA miles in $TimeA hours at $SpeedA mph.
"; echo "Train B traveled $DistanceB miles in $TimeB hours at $SpeedB mph.
"; echo "The sum of the two distances is ".($DistanceA + $DistanceB)."miles.
"; } } //check if data entered is numeric if(isset($_POST['Submit'])) { $SpeedA = validateInput($_POST['speedA'], "Speed of Train A"); $SpeedB = validateInput($_POST['speedB'], "Speed of Train B"); $Distance = validateInput($_POST['distance'], "Distance between trains"); //check error count if($errorCount == 0) { $DisplayForm = FALSE; } else { $DisplayForm = TRUE; } //display the form function displayForm($SpeedA, $SpeedB, $Distance) { ?>
Two Trains
"; ++$errorCount; $retval = " "; } else { $retval = trim($data); $retval = $stipslashes($retval); //check if input is numeric if(is_numeric($retval)){ //check value of input if($retval <= 0) { echo "\"$fieldName\" must be a number greater than 0."; ++$errorCount; } } else {//if input is not numeric echo "\"$fieldName\" must be a number.
"; ++$errorCount; $retval = " "; } } return($retval); } ?>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
