Disclaimer: I am extremely new to programming! I have taken one C++ class and am currently taking a PHP class. I have an assignment to "Create a Web form that shows the mileage between European capitals. Use a two-dimensional associative array to store the mileages."
I have wrote the code, moved it around to different places, deleted things, added things, and I continuously get error message that says it was expecting the end of the file. I will post what I have below. I am looking for guided help and not just the answer. I have re-read the chapter and if I'm being honest, I don't completely understand it. This is our 7 or 8th assignment and this is the first one I have had to reach out for help. I appreciate any assistance that anyone is willing to give. Thanks in advance!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<title>European Travel</title>
</head>
<body>
<p>
</p>
</body>
</html>
<?php
$Distances = array(
"Berlin" => array(
"Berlin" => 0,
"Moscow" =>1607.99,
"Paris" => 876.96,
"Prague" => 280.34,
"Rome" => 1181.67
),
"Moscow" => array(
"Berlin" => 1607.99,
"Moscow" => 0,
"Paris" => 2484.92,
"Prague" => 1664.04,
"Rome" => 2374.26
),
"Paris" => array(
"Berlin" => 876.96,
"Moscow" => 641.31,
"Paris" => 0,
"Prague" => 885.38,
"Rome" => 1105.76
),
"Prague" => array(
"Berlin" => 280.34,
"Moscow" => 1664.04,
"Paris" => 885.38,
"Prague" => 0,
"Rome" => 922
),
"Rome" => array(
"Berlin" => 1181.67,
"Moscow" => 2374.26,
"Paris" => 1105.76,
"Prague" => 922,
"Rome" => 0
)
);
$StartIndex = "";
$EndIndex = "";
$KMtoMiles = 0.62;
if (isset($_POST['submit'])) {
$StartIndex = stripslashes($_POST['Start']);
$EndIndex = stripslashes($_POST['End']);
if (isset(
$Distances[$StartIndex][$EndIndex]))
echo "<p>The distance from $StartIndex
to $EndIndex is " .
$Distances[$StartIndex][$EndIndex]
. " kilometers, or " . round(
($KMtoMiles *
$Distances[$StartIndex][$EndIndex]),
2) . " miles.</p>\n";
else
echo "<p>The distance from $StartIndex
to $EndIndex is not in the
array.</p>\n";
}
foreach ($Distances as
$City => $OtherCities) {
echo "<option value='$City'";
if (strcmp($StartIndex,$City)==0)
echo " selected";
echo ">$City</option>\n";
}
foreach ($Distances as
$City => $OtherCities) {
echo "<option value='$City'";
if (strcmp($EndIndex,$City)==0)
echo " selected";
echo ">$City</option>\n";
}
<form action="EuropeanTravel.php" method="post">
<p>Starting City:
<select name="Start">
</select></p>
<p>Ending City:
<select name="End">
</select></p>
<p><input type="submit" name="submit"
value="Calculate Distance" /></p>
</form>
?>