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>

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;
     }
}
?>

this shud help:

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.