How to display the data when user click on booking id

Hi

All

I am displaying the data from booking table which is showing the booking id, customer name.

the code is
<?php
$result = mysql_query(“SELECT * FROM zeetemp”)
or die(mysql_error());

echo “<table border=‘0’ bgcolor=‘#F5A9D0’>”;
echo “<tr> <th>booking</th><th>contact_name</th><th>vehicle</th> <th>Pickup_addr</tr>”;
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo “<tr><td>”;
echo "<a href=$row[‘booking_id’];
echo “</td><td>”;
echo $row[‘contact_name’];
echo “</td></tr>”;
}

echo “</table>”;
?>
This will display the booking id and customer name

like

BK001 Johnmathew

Now i want to display the complete details of john mathew if clicks on the BK001.
and it should display in form

Any help is greatly appreciated.

Thanks & Regards

MD.Samiuddin

You want to get PHP to make you a link which is similar to this in your loop:


<a href="booking.php?id=BK001">BK001</a>

Then in booking.php, you check that id a) is not too long nor not too short and b) contains only ‘BK’ and numbers - because someone can very easily tamper with these values in your browser in order to break you site.

I will presume you booking table contains bookings with an auto-incrementing id table, so having filtered the incoming id variable you take off the ‘BK’ and turn the 001 into a variable: example:


$id = 'BK001';

$real_id (int)substr($id, 2);  // gives 1

Now, if $real_id is greater than 0, you can go ahead and simply craft an sql statement as you would normally:


$sql = "select booking_details from bookings where id = $real_id ";

echoing $sql onto a page as you work things out is also a good idea.

select booking_details from bookings where id = 1

This allows you to a) see what PHP has done on your behalf, and b) paste that statement into your database and make sure you have some matching data in the database - otherwise you could get everything right and still risk losing your mind. :wink: