I'm doing a flight booking site with PHP for my assignment. The search page returns a table of related flight details from the key word that was entered. Then in the table it gives the option to choose only one flight to book. After selecting a certain flight by radio button and clicking "make booking for selected flight" button, the next page is required to display the flight details that have been selected from the previous page.
The problem is: how do I display the selected flight details?
Pass some unique identifier from your flight to the details page via URL variable. To access those variables, simply use the PHP $_GET['id']
variable (in this case to access a url variable named id
).
To pass an "id" url variable, simply append ?id=value
to your redirect: http://page.com/details.php?id=5
Once you have this on your second page, it is very easy to do another MySQL query to retrieve the details from flight, say, 5 and display it on the second page.
I'm sure you did use the form for user to selected the appropriate options. Let's say:
<form action="nextpage.php" method="post">
<input type="radio" name="flight" value="flight1" />Option 1<br />
<input type="radio" name="flight" value="flight2" />Option 2<br />
......
<input type="submit" name="booking" value="Make Booking for the Selected Flight" />
</form>
Then on page nextpage.php
you can get the flight that user have selected by using the php code below:
<?php
$flight = $_POST['flight'];
//do things u need here, for example
echo $flight;
?>
You can use following method to send data on next page.
1) Session
2) Cookies
3) Get method
4) Post method(Using hidden fields).