Help Please

My project: http://207.233.9.11/PHPClass/bwood/midterm/index.html and assignment for my project:
http://207.233.9.11/PHPClass/bwood/midterm/assigment.html

I can’t seem to get the last part right checking the paces. Any help would be awesome. Here is my PHP:
[php]<?php
/ERROR VALIDATIONS/
$formError = 0;
/FIRST AND LAST NAME ERROR VAL/
if (empty($_POST[“first_name”]) || is_numeric($_POST[“first_name”])){
$firstNameErrorMsg = “Please enter a valid First Name! Example: John
”;
$formError = 1;
}
if(empty($_POST[“last_name”]) || is_numeric($_POST[“last_name”])){
$lastNameErrorMsg = “Please enter a valid Last Name! Example: Doe.
”;
$formError = 1;
}
/DATE ERRORS/
if(empty($_POST[“month”]) || !is_numeric($_POST[“month”]) || $_POST[“month”]<1 || $_POST[“month”]>12 || $_POST[“month”]<= -1){
$monthError = “Please enter a valid Month! Example: 01 - 12 please!
”;
$formError = 1;
}
if(empty($_POST[“day”]) || !is_numeric($_POST[“day”]) || $_POST[“day”]<1 || $_POST[“day”]>31 || $_POST[“day”]<= -1){
$dayError = “Please enter a valid Day! 1 - 31 please!
”;
$formError = 1;
}
if(empty($_POST[“year”]) || !is_numeric($_POST[“year”]) || $_POST[“year”]<2010 || $_POST[“year”]>2030 || $_POST[“year”]<= 0){
$yearError = “Please enter a valid Year! Between 2010 and 2030 please!
”;
$formError = 1;
}
/COACH NAME/
if (empty($_POST[“coach_name”]) || is_numeric($_POST[“coach_name”])){
$coachNameError = “Please enter your Coach’s name correctly!
”;
$formError = 1;
}
/CHECK DISTANCE AND TIME/
if (empty($_POST[“race_distance”]) || !is_numeric($_POST[“race_distance”]) || $_POST[“race_distance”] <= 0){
$raceDistanceError = “Please enter your race distance, or use numbers!
”;
$formError = 1;
}
if(empty($_POST[“time0”]) || !is_numeric($_POST[“time0”]) || $_POST[“time0”] <= 0){
$raceTimeError = “Please enter a correct race time!
”;
$formError = 1;
}
if (empty($_POST[‘email_address’]) || !filter_var($_POST[‘email_address’], FILTER_VALIDATE_EMAIL)) {
$formatEmailError = “Please enter a valid email address!
”;
$formError = 1;
}
/**/

if ($formError){
print “You have errors in this form. Please Address the following errors to continue:
”;
if(!empty($firstNameErrorMsg)){
print $firstNameErrorMsg;
print “
”;
}
if(!empty($lastNameErrorMsg)){
print $lastNameErrorMsg;
print “
”;
}
if(!empty($monthError)){
print $monthError;
print “
”;
}
if(!empty($dayError)){
print $dayError;
print “
”;
}
if(!empty($yearError)){
print $yearError;
print “
”;
}
if(!empty($coachNameError)){
print $coachNameError;
print “
”;
}
if(!empty($formatEmailError)){
print $formatEmailError;
print “
”;
}
if(!empty($raceDistanceError)){
print $raceDistanceError;
print “
”;
}
if(!empty($raceTimeError)){
print $raceTimeError;
print “
”;
}
print “Please click Here to go back and fix them.”;

}
else{
	$first_name = $_POST["first_name"];
	$first_name = strip_tags($first_name);
	$first_name = trim($first_name);
	$first_name = ucfirst($first_name);
	$last_name = $_POST["last_name"];
	$last_name = strip_tags($last_name);
	$last_name = trim($last_name);
	$last_name = ucfirst($last_name);
	/*Runner Full Name*/
	$runnerFullName = (string)$first_name." ".$last_name;
	/*DATE*/
	$day = $_POST["day"]; 
	$month = $_POST["month"];
	$year = $_POST["year"];
	/*Coach Name*/
	$coach_name = $_POST["coach_name"];
	$coach_name = trim($coach_name);
	$coach_name = strip_tags($coach_name);
	$coach_name = ucwords($coach_name);
	/*Email Address*/
	$email_address = $_POST["email_address"];
	/*Race Distance and Time*/
	$race_distance = $_POST["race_distance"];
	$race_distance = strip_tags($race_distance);
	$race_distance = trim($race_distance);
	$distanceUnits = $_POST["distanceUnits"];
	$time0 = $_POST["time0"];
	$time0 = strip_tags($time0);
	$timeUnits = $_POST["timeUnits"];
	/*COMMENTS*/
	$comments = $_POST["comments"];
	$comments = strip_tags($comments);
	$comments = nl2br($comments);
	$charCount = strlen($comments);

/INTERVALS/

/RUNNING PACE/
$pace1 = $_POST[“pace1”];
$pace1 = strip_tags($pace1);
$pace2 = $_POST[“pace2”];
$pace2 = strip_tags($pace2);
$pace3 = $_POST[“pace3”];
$pace3 = strip_tags($pace3);
/TIME ALLOCATED PER INTERVAL/
$time1 = $_POST[“time1”];
$time1 = strip_tags($time1);
$time2 = $_POST[“time2”];
$time2 = strip_tags($time2);
$time3 = $_POST[“time3”];
$time3 = strip_tags($time3);
/UNITS OF MEASURE FOR PACE AND TIME PACE/
$units_pace = $_POST[“units_pace”]; //miles/hour or km/hr
$units_time_pace = $_POST[“units_time_pace”]; //hours and minutes
}
if ($distanceUnits == “kilo” && !“miles”){
$raceDistanceConverted = 0;
$raceDistanceConverted = ($race_distance / 1.609);//kilometers
$raceDistanceConverted = $kilometers;
$kilometers = number_format($kilometers, 2). " “.“Km”;
}
else{
$raceDistanceConverted = $race_distance.” ".“MPH”; //miles
}
if ($timeUnits == “hours”){
$hours = $timeUnits; //Regular Hours
$timeDisplay = “Hour(s)”;
$hoursToMinutes = ($time0 * 60); //Hours to Minutes
}
else{
$minutes = $timeUnits; //Regular Minutes
$timeDisplay = “Mintues”;
}
print "Race Overview:

Distance: $race_distance

Time: $time0 $timeDisplay
";

if($_POST[“intervals”]; == 4 && empty($pace1) || empty($time1)){
$errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals ==4 && empty($pace2) || empty($time2)){
$errorPace2 = “Pace 2 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals ==4 && empty($pace3) || empty($time3)){
$errorPace3 = “Pace 3 time and or distance is empty, please fill them out!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * time1);
$distance2 = ($pace2 * time2);
$distance2 = ($pace3 * time3);
$distance_last4 = $race_distance - ($distance1 - $distance2);
$time_last4 = $time0 - ($time1 - $time2);
$lastInterval4 = ($distance_last4 / $time_last4);
}
if($intervals == 3 && empty($pace1) || empty($time1)){
$in2errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals ==3 && empty($pace2) || empty($time2)){
$in2errorPace2 = “Pace 2 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals ==3 && !empty($pace3) || !empty($time3)){
$in2errorPace3 = “Pace 3 time and or distance is already being calculated!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * time1);
$distance2 = ($pace2 * time2);
$distance_last3 = $race_distance - ($distance1 - $distance2);
$time_last3 = $time0 - ($time1 - $time2);
$lastInterval3 = ($distance_last3 / $time_last3);
}
if($intervals == 2 && empty($pace1) || empty($time1)){
$in3errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals ==2 && !empty($pace2) || !empty($time2)){
$in3errorPace2 = “Pace 2 time and distance is already being calculated!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * time1);
$distance_last2 = ($race_distance - $distance1);
$time_last2 = ($time0 - $time1);
$lastInterval2 = ($distance_last2 / $time_last2);
}

/* if($no_intervals == 3 && !empty($pace1) || !empty($time1)){
$errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
if(!empty($pace2) || !empty($time2)){
$errorPace2 = “Pace 2 time and or distance is empty, please fill them out!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * time1);
$distance2 = ($pace2 * time2);
$distance_last3 = $race_distance - ($distance1 - $distance2);
$time_last3 = $time0 - ($time1 - $time2);
$lastInterval3 = ($distance_last3 / $time_last3);
}
if($no_intervals == 2 && !empty($pace1) || !empty($time1)){
$errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * time1);
$distance_last2 = ($race_distance - $distance1);
$time_last2 = ($time0 - $time1);
$lastInterval2 = ($distance_last2 / $time_last2);
}
else{
$pace1 = $_POST[“pace1”];
$pace2 = $_POST[“pace2”];
$pace3 = $_POST[“pace3”];
$time1 = $_POST[“time1”];
$time2 = $_POST[“time2”];
$time3 = $_POST[“time3”];
$distance1 = ($pace1 * time1);
$distance2 = ($pace2 * time2);
$distance3 = ($pace3 * time3);
$distance_last4 = $race_distance - ($distance1 - $distance2 - $distance3);
$time_last4 = $time0 - ($time1 - $time2 - $time3);
$lastInterval4 = $distance_last4 / $time_last4;
}
*/

?>[/php]

It is rather long so only brave people attempt to help.

Thanks!

I have updated my PHP code since. I am having problems with the calculations and the pace errors are kinda shady.

[php]

Midterm - Calculations Page <?php /*ERROR VALIDATIONS*/ $formError = 0; /*FIRST AND LAST NAME ERROR VAL*/ if (empty($_POST["first_name"]) || is_numeric($_POST["first_name"])){ $firstNameErrorMsg = "Please enter a valid First Name! Example: John
"; $formError = 1; } if(empty($_POST["last_name"]) || is_numeric($_POST["last_name"])){ $lastNameErrorMsg = "Please enter a valid Last Name! Example: Doe.
"; $formError = 1; } /*DATE ERRORS*/ if(empty($_POST["month"]) || !is_numeric($_POST["month"]) || $_POST["month"]<1 || $_POST["month"]>12 || $_POST["month"]<= -1){ $monthError = "Please enter a valid Month! Example: 01 - 12 please!
"; $formError = 1; } if(empty($_POST["day"]) || !is_numeric($_POST["day"]) || $_POST["day"]<1 || $_POST["day"]>31 || $_POST["day"]<= -1){ $dayError = "Please enter a valid Day! 1 - 31 please!
"; $formError = 1; } if(empty($_POST["year"]) || !is_numeric($_POST["year"]) || $_POST["year"]<2010 || $_POST["year"]>2030 || $_POST["year"]<= 0){ $yearError = "Please enter a valid Year! Between 2010 and 2030 please!
"; $formError = 1; } /*COACH NAME*/ if (empty($_POST["coach_name"]) || is_numeric($_POST["coach_name"])){ $coachNameError = "Please enter your Coach's name correctly!
"; $formError = 1; } /*CHECK DISTANCE AND TIME*/ if (empty($_POST["race_distance"]) || !is_numeric($_POST["race_distance"]) || $_POST["race_distance"] <= 0){ $raceDistanceError = "Please enter your race distance, or use numbers!
"; $formError = 1; } if(empty($_POST["time0"]) || !is_numeric($_POST["time0"]) || $_POST["time0"] <= 0){ $raceTimeError = "Please enter a correct race time!
"; $formError = 1; } if (empty($_POST['email_address']) || !filter_var($_POST['email_address'], FILTER_VALIDATE_EMAIL)) { $formatEmailError = "Please enter a valid email address!
"; $formError = 1; } /**/

if ($formError){
print “You have errors in this form. Please Address the following errors to continue:
”;
if(!empty($firstNameErrorMsg)){
print $firstNameErrorMsg;
print “
”;
}
if(!empty($lastNameErrorMsg)){
print $lastNameErrorMsg;
print “
”;
}
if(!empty($monthError)){
print $monthError;
print “
”;
}
if(!empty($dayError)){
print $dayError;
print “
”;
}
if(!empty($yearError)){
print $yearError;
print “
”;
}
if(!empty($coachNameError)){
print $coachNameError;
print “
”;
}
if(!empty($formatEmailError)){
print $formatEmailError;
print “
”;
}
if(!empty($raceDistanceError)){
print $raceDistanceError;
print “
”;
}
if(!empty($raceTimeError)){
print $raceTimeError;
print “
”;
}
print “Please click Here to go back and fix them.”;

}
else{
	$first_name = $_POST["first_name"];
	$first_name = strip_tags($first_name);
	$first_name = trim($first_name);
	$first_name = ucfirst($first_name);
	$last_name = $_POST["last_name"];
	$last_name = strip_tags($last_name);
	$last_name = trim($last_name);
	$last_name = ucfirst($last_name);
	/*Runner Full Name*/
	$runnerFullName = (string)$first_name." ".$last_name;
	/*DATE*/
	$day = $_POST["day"]; 
	$month = $_POST["month"];
	$year = $_POST["year"];
	/*Coach Name*/
	$coach_name = $_POST["coach_name"];
	$coach_name = trim($coach_name);
	$coach_name = strip_tags($coach_name);
	$coach_name = ucwords($coach_name);
	/*Email Address*/
	$email_address = $_POST["email_address"];
	/*Race Distance and Time*/
	$race_distance = $_POST["race_distance"];
	$race_distance = strip_tags($race_distance);
	$race_distance = trim($race_distance);
	$distanceUnits = $_POST["distanceUnits"];
	$time0 = $_POST["time0"];
	$time0 = strip_tags($time0);
	$timeUnits = $_POST["timeUnits"];
	/*COMMENTS*/
	$comments = $_POST["comments"];
	$comments = strip_tags($comments);
	$comments = nl2br($comments);
	$charCount = strlen($comments);
	/*INTERVALS*/ 
	/*RUNNING PACE*/
	$pace1 = $_POST["pace1"];
	$pace1 = strip_tags($pace1);
	$pace2 = $_POST["pace2"];
	$pace2 = strip_tags($pace2);
	$pace3 = $_POST["pace3"];
	$pace3 = strip_tags($pace3);
	/*TIME ALLOCATED PER INTERVAL*/
	$time1 = $_POST["time1"];
	$time1 = strip_tags($time1);
	$time2 = $_POST["time2"];
	$time2 = strip_tags($time2);
	$time3 = $_POST["time3"];
	$time3 = strip_tags($time3);
	/*UNITS OF MEASURE FOR PACE AND TIME PACE*/
	$units_pace = $_POST["units_pace"]; //miles/hour or km/hr
	$units_time_pace = $_POST["units_time_pace"]; //hours and minutes

}
if ($distanceUnits == “kilo” && !“miles”){
$raceDistanceConverted = 0;
$raceDistanceConverted = ($race_distance / 1.609);//kilometers
$raceDistanceConverted = $kilometers;
$kilometers = number_format($kilometers, 2). " “.“Km”;
}
else{
$raceDistanceConverted = $race_distance.” ".“MPH”; //miles
}
if ($timeUnits == “hours”){
$hours = $timeUnits; //Regular Hours
$timeDisplay = “Hour(s)”;
$hoursToMinutes = ($time0 * 60); //Hours to Minutes
}
else{
$minutes = $timeUnits; //Regular Minutes
$timeDisplay = “Mintues”;
}
$intervals = $_POST[“intervals”];
print "Race Overview:

Distance: $race_distance

Time: $time0 $timeDisplay
";

if($intervals == 4 && empty($pace1) || empty($time1)){
$errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals == 4 && empty($pace2) || empty($time2)){
$errorPace2 = “Pace 2 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals == 4 && empty($pace3) || empty($time3)){
$errorPace3 = “Pace 3 time and or distance is empty, please fill them out!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * $time1);
$distance2 = ($pace2 * $time2);
$distance2 = ($pace3 * $time3);
$distance_last4 = $race_distance - ($distance1 - $distance2);
$time_last4 = $time0 - ($time1 - $time2);
$lastInterval4 = ($distance_last4 / $time_last4);
}
if($intervals == 3 && empty($pace1) || empty($time1)){
$in2errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals == 3 && empty($pace2) || empty($time2)){
$in2errorPace2 = “Pace 2 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals == 3 && !empty($pace3) || !empty($time3)){
$in2errorPace3 = “Pace 3 time and or distance is already being calculated!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * $time1);
$distance2 = ($pace2 * $time2);
$distance_last3 = $race_distance - ($distance1 - $distance2);
$time_last3 = $time0 - ($time1 - $time2);
$lastInterval3 = ($distance_last3 / $time_last3);
}
if($intervals == 2 && empty($pace1) || empty($time1)){
$in3errorPace1 = “Pace 1 time and or distance is empty, please fill them out!”;
$formError = 1;
}
elseif($intervals ==2 && !empty($pace2) || !empty($time2)){
$in3errorPace2 = “Pace 2 time and distance is already being calculated!”;
$formError = 1;
}
else{
$distance1 = ($pace1 * time1);
$distance_last2 = ($race_distance - $distance1);
$time_last2 = ($time0 - $time1);
$lastInterval2 = ($distance_last2 / $time_last2);
}
if($formError){
if(!empty($errorPace1)){
print $errorPace1;
print “
”;
}
if(!empty($errorPace2)){
print $errorPace2;
print “
”;
}
if(!empty($errorPace3)){
print $errorPace3;
print “
”;
}
if(!empty($in2errorPace1)){
print $in2errorPace1;
print “
”;
}
if(!empty($in2errorPace2)){
print $in2errorPace2;
print “
”;
}
if(!empty($in2errorPace3)){
print $in2errorPace3;
print “
”;
}
if(!empty($in3errorPace1)){
print $in3errorPace1;
print “
”;
}
if(!empty($in3errorPace2)){
print $in3errorPace2;
print “
”;
}

}


?>
[/php]

What needs fixing? What errors are you getting. I only saw one issue. There is one print statement that has a hidden variable inside it that I doubt would print. Perhaps that is what you are talking about.

Try changing this code:
print "Race Overview:

Distance: $race_distance

Time: $time0 $timeDisplay
";

To this version:
[php]
print “Race Overview:
Distance:” . $race_distance . “
Time:” . $time0 . " " . $timeDisplay . “
”;
[/php]
Normally you add variables outside of string text. Hope that is what you wanted… Let us know.

I am trying to come up with a Distance and Time Conversion method. Like if on my form your Race Distance is Miles but you chose Kilo/Hour on your pace, I need to convert for each of my Condition statements checking the intervals 1-4. My Code is at http://207.233.9.11/PHPClass/bwood/midterm/code.html and my page is index.html.

Any Help would be great.

This group

if ($distanceUnits == “kilo” && !“miles”){
$raceDistanceConverted = 0;
$raceDistanceConverted = ($race_distance / 1.609);//kilometers $raceDistanceConverted = $kilometers;
$kilometers = number_format($kilometers, 2). " ".“Km”;
}

can be condensed to

if ($distanceUnits == “kilo” && !“miles”) {
$raceDistanceConverted = numberformat(($race_distance / 1.609), 2). " Km"; //kilometers
}

Sponsor our Newsletter | Privacy Policy | Terms of Service