I am trying to do a “all in one” form that lets the user input data and then then some of the data is then multiplied, some divided, some added, and some subtracted. I made the form ok but I do not understand how to get the data to display. I have looked at alot of tutorials but I am just not getting it. To be honest this was an assignment for a class but I have already turned it in with the math part not working. I just want to be able to understand how to do it. If someone could please work with me on this I would really appreciate it. I feel like I should get this part before I go on but the class will move on without me.
Post what you have so far
This is what I have so far. I am thinking that I need to do a “Function DisplayDistance”, DisplayTime, and so on but I am not sure.
[php]
Two Trains <?php function validateInput($data, $fieldName) { global $errorCount; if (empty($data)) { echo "\"$fieldName\" is a required field.\n"; ++$errorCount; $retval = ""; } else { $retval = trim($data); $retval = stripslashes($retval); } return($retval); } function validateDistance($data, $fieldName) { global $errorCount; if (empty($data)) { echo "\"$fieldName\" is a required field.
\n"; ++$errorCount; $retval = ""; } else { $retval = trim($data); $retval = stripslashes($retval); $pattern = "/^[\w-]+(\.[\w-]+)*@"."[\w-]+(\.[\w-]+)*". "(\.[[a-z]]{2,})$/i"; if (preg_match($pattern, $retval)==0) { echo "\"$fieldName\" division by zero not allowed.
\n;"; ++$errorCount; } } return($retval); } function displayForm($SpeedA, $SpeedB, $Distance) { ?>
Two Trains
SpeedA:
SpeedB:
Distance:
<?php } $ShowForm = TRUE; $errorCount = 0; $SpeedA = ""; $SpeedB = ""; $Distance = ""; if (isset($_Post['Submit'])) { $SpeedA = validateInput($_POST['SpeedA'], "SpeedA"); $SpeedB = validateInput($_POST['SpeedB'], "SpeedB"); $Distance = validateInput($_POST['Distance'], "Distance"); if ($errorCount==0) $ShowForm = FALSE; else $ShowForm = TRUE; } if ($ShowForm == TRUE) { if ($errorCount>0) echo "
Please re-enter the speeds below.
\n"; displayForm($SpeedA, $SpeedB, $Distance); } else { $DistanceA = (($SpeedA / $SpeedB) * $Distance) /
(1 + ($SpeedA / $SpeedB));
echo "Distance Traveled By Train A = $DistanceA<br />";
$DistanceB = $Distance - $DistanceA;
echo "Distance Traveled By Train B = $DistanceB<br />";
$TimeA = $DistanceA / $SpeedA;
echo "Time Traveled By Train A = $TimeA<br />";
$TimeB = $DistanceB / $SpeedB;
echo "Distance Traveled By Train B = $TimeB<br />";
}
?>
[/php]Right here:
[php]if (isset($_Post[‘Submit’])) {[/php]
$_Post needs to be $_POST
This seems to be a common mistake around here lately
Thank you so much for the help.