0

Hello, I am new on this website. I don't know rather I am in the right place or not. I am currently in college and study to be web developer. I am doing good so far! I really need help on this small part. We are working on Mulipulating Strings. The assignment wants me to make script for person to enter how many miles to travel, and how many stops in 2 different weather condition. Good weather to travel 50 mph while bad weather travel 40 mph. Each stop add up 5 minutes. The assignment want one script, not using .html plus .php. Only one php that has both in one. This is what I got so far, the good weather works! but the bad weather is also work and it has line 40 that it didn't like! How do i figure this out? What did I do wrong?

<body>
<form action="PassengerTrain.php" method="get" 
enctype="application/x-www-form-urlencoded">

<h1>Passenger Train</h1>

<h3>Number of miles</h3>
<input type="text" name="mile" size="6">
Miles<br />

<h3>Number of stops</h3>
<input type="text" name="stop" size="3">
Stops

<h3>Please Select Weather Condition</h3>

<input type="radio" name="good" />
Good Weather Condition<br />
<input type="radio" name="bad" />
Bad Weather Condition
<p><input type="reset" />
<input type="submit" />
</form>

<?php
While($_GET) {
$k = $_GET['mile'];
$l = $_GET['stop'];
$MinTotal = $l*.05;
   if ($_GET['good']) {
   $MilTotal = $k/50;
        echo "You selected Good Weather Condition and to travel $k miles with $l stops; 
        the total hours/minutes are ", $MilTotal+$MinTotal;
        break;

}
if ($_GET['bad']) {
   $MilTotal = $k/40;
        echo "You selected Bad Weather Condition and to travel $k miles with $l stops; 
        the total hours/minutes are ", $MilTotal+$MinTotal;
        break;
    }
}
?>
</body>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by bibiki
0

I got the figure out to get php to work. Which is part of mission successful but my math figure isn't right. I need to figure out how to get hours and minute set up right instead of 6.8333333333333 I am not sure what to do but will contiune to figure out how. If someone has suggestion how to fix my math error, that would be great thanks!

<?php
While($_GET) {
$k = $_GET['mile'];
$l = $_GET['stop'];
$MinTotal = $l*5;

   if (isset($_GET['good'])) {
   $MilTotal = $k/50;
        echo "You selected Good Weather Condition and to travel $k miles with $l stops; 
        the total hours/minutes are ", $MilTotal+$MinTotal;
        break;
      }
   else
     if (isset($_GET['bad'])) {
     $MilTotal = $k/40;
        echo "You selected Bad Weather Condition and to travel $k miles with $l stops; 
        the total hours/minutes are ", $MilTotal+$MinTotal;
        break;
     }
}
?>
0

this shud help:

<?php
				$total = $MilTotal+$MinTotal;
				$hr = floor(($total*60)/60);
				$mins = ($total*60)%60;
				echo "hours:".$hr;
				echo "mins:".$mins;
 			?>
0

one thing you might want to consider is that when you built up the list of weather options from which to chose, you created two separate input lists. as a result, one may select both, bad and good wether. in that case, the isset($_GET would return true even if both are selected, which would, i assume, give out a result, and that's not what you want.

the form should rather have one input for weather, with two possible values. what you have is:

<input type="radio" name="good" />
Good Weather Condition<br />
<input type="radio" name="bad" />

note that you have two inputs, one good, one bad. you should have one input (one name for both), and two values (one for each).
then, when you do your if-test, do not use the isset(). rather, test whether $_GET equals one of the values. hope that helps!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.