I am totally new to scripting, basically i have to try and finish a school project on a coaching tour project. The idea is to allow customers to register and book a tour.
What i am having problem with is, i have no idea on how to create a dynamic drop down list where the booking form will take the data from mysql database.
Lets say for example :
The customer needs to select a choice of tour i.e (industrial, cultural, military) from the first drop down list.
After selecting a tour, the next drop down list should list the destinations i.e. (UK, France, Germany, etc) dependant on the above (tour) choice.
Then the third list should show the start dates dependant on the above (destination) choice.
All the data in the drop down list should come from the database. Also when the customer submits the form, all those data should go into the customers booking table in the database.
I was told that javascript should be the answer, but i have searched so many forums and look at tutorials which they are all confusing. Hence I came to ask here! Any help on how to do this is much appreciated. Thnx!
Below is the code of how i only know how to do this:
<h2><center>PLEASE PLACE YOUR BOOKING</center></h2>
<form action="booking.php" method="post">
<table width="700 border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td width="210" height="45">Tour Type:</td><td>
<select name="tour_type">
<option value="Cultural">Cultural</option>
<option value="Industrial">Industrial</option>
<option value="Military">Military</option>
</select></td></tr>
<tr><td width="210" height="45">Duration:</td><td>
<select name="duration" >
<option value="1_Day">1_Day</option>
<option value="7_Days">7_Days</option>
<option value="14_Days">14_Days</option>
</select></td></tr>
<tr><td width="210" height="45">Destination:</td><td>
<select name="destination" >
<option value="England">England</option>
<option value="Wales">Wales</option>
<option value="Scotland">Scotland</option>
<option value="France">France</option>
<option value="Belgium">Belgium</option>
<option value="Germany">Germany</option>
</select></td></tr>
<tr><td width="210" height="45">No. of Passengers:</td><td>
<select name="no_of_passengers" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select></td></tr>
<tr><td width="210" height="45">Depature:</td><td>
<select name="departure" >
<option value="13 May 2013">13 May 2013</option>
<option value="28 May 2013">28 May 2013</option>
<option value="11 June 2013">11 June 2013</option>
<option value="26 June 2013">26 June 2013</option>
<option value="14 July 2013">14 July 2013</option>
<option value="27 July 2013">27 July 2013</option>
</select></td></tr>
<tr><td width="210" height="45"><input type="checkbox" name="accomodation"
value="YES"/>Accomodation</td></tr>
<tr><td width="210" height="45"><input type="checkbox" name="mailshot"
value="YES"/>Mailshot</td></tr>
<tr><td width="210" height="45"><input type="submit" name="submit" value="submit"></td></tr>
</table>
</form>
</html>
<?php
//When submit button is pressed.
if (isset($_POST['submit'])) {
//Include the server and database connection.
include('cn.php');
session_start();
//retrieve data input from booking form and make it equal to the variable ($)
$tour_type = $_POST['tour_type'];
$duration = $_POST['duration'];
$destination = $_POST['destination'];
$no_of_passengers = $_POST['no_of_passengers'];
$departure = $_POST['departure'];
// accomodation confirmation
if (isset($_POST['accomodation'] ))
{$accom = $_POST["accomodation"];
} else {
$accom = "NO";
}
// mailshot confirmation
if (isset($_POST['mailshot'] ))
{$mail = $_POST["mailshot"];
} else {
$mail = "NO";
}
$userUsername = $_SESSION['loggedInUser'];
// Build the SQL query to retreive the variables ($) and input the data into the database.
$sql = "INSERT INTO booking
(user_id,tour_type,duration,destination,no_of_passengers,departure,accomodation,mailshot)
VALUES ((SELECT user_id FROM user WHERE user_username = '" .
$userUsername . "'),'$tour_type','$duration','$destination',
'$no_of_passengers','$departure','$accom' ,'$mail')";
// test the sql statement.
if(!mysql_query($sql,$cn)) {
die(mysql_error($cn));
}
// direct to this page when booking is successful.
header('Location: booking_success.php');
}
?>