So, I'm at a bit of a lost when it comes to submitting a form and returning data based on what was selected in a drop-down list.
My current drop-down list is populated with flights, gathered from a database.
My question is, once a flight is picked from the drop-down list and the submit button has been pressed, how do I go about returning more information? (Once a flight is picked, I want to show the list of passengers on that flight)
<!DOCTYPE html>
<html>
<head>
<style>
body { /*Set default text color used in body*/
color: #ff8306;
}
</style>
<title>1234</title>
</head>
<body bgcolor="#0a06ff"> <!-- Set default background color-->
<p align="center">List of all passengers: <br>
<?php
$sqlRequest = "SELECT firstName, lastName FROM passenger ORDER BY lastName"; //Select the passenger first namw and last, in alphabetic order of lastname
$result = $connection->query($sqlRequest); //save result
if($result->num_rows > 0) { //print out the names in alphabetic order of lastname in rows
while($row = $result->fetch_assoc()) {
echo $row["firstName"]. " ". $row["lastName"]. "<br>";
}
}
?>
</p>
<form align="center" action="flit.php" method="post">
<fieldset>
<legend>Flight Information</legend>
<?php
$sqlRequest = "SELECT flightnum, origination, destination FROM flight";
$result = $connection->query($sqlRequest);
echo "Select a flight:". "<br>";
echo "<Select Flight='flight'>";
while ($row = $result->fetch_assoc()) { //populate dropdown with flights
echo "<option value='". $row['flightnum']. "'>". $row['flightnum']. ": ". $row['origination']. " to ". $row['destination']. "</option>";
}
echo "</select>";
echo '<button type="Submit" value="Submit">Submit</button>';
?>
</fieldset>
</form>
</body>
</html>
Just in case, here are my tables,
Flight table:
flight (flightnum int auto_increment primary key, origination char(25), destination char(25),miles int)
Passenger Table:
passenger(passnum int auto_increment primary key, lastName char(10), firstName char(10) )
Manifest Table
manifest(flightnum int, flightDate date, passnum int, seatnum char(5),
primary key(flightnum, flightDate, passnum),
foreign key(flightnum) references flight(flightnum) ,
foreign key(passnum) references passenger(passnum))