Question: Problem: While my code validates concerning syntax, I can't get the form to even display (unless I create a form in HTML first). This a
Problem: While my code validates concerning syntax, I can't get the form to even display (unless I create a form in HTML first). This a problem from "PHP Programming with MySQL" Second Edition, Chapter 4, Exercise 4-5 if you need more details. I've reread the text, but I can't figure out what I'm doing wrong. My code is pasted below, thanks in advance for any suggestions.
Requirements: Create an all-in-one sticky form with two functions: one to validate the input as numeric and greater than zero and one to display the form. Plus extra code to execute the functions.
Here is a link to the actual problem: https://www.chegg.com/homework-help/php-programming-with-mysql-2nd-edition-chapter-4-problem-5re-solution-9780538745840
Here is a link to how the program should run (this is not my work): http://j-journey.com/Chapter.04/Chapter_Homework/Ch%204_teacher%20Solution/TwoTrains.php
MY CODE
Two Trains
"; echo "Train B traveled ".$DistanceB."miles in ".$TimeB."hours at ".$SpeedB."mph."; echo "The sum of the two distances is ".($DistanceA + $DistanceB)."miles.
"; } else { echo "Please re-enter the form information below.
"; displayForm($SpeedA, $SpeedB, $Distance); } } //validate input function validateInput($data, $fieldName) { global $errorCount; if(empty($data)) { echo "\"$fieldName\" is a required field.
"; ++$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
