我对脚本完全陌生,基本上我必须尝试完成一个关于辅导旅游项目的学校项目。这个想法是允许客户注册和预订旅游。
我遇到的问题是,我不知道如何创建一个动态下拉列表,其中预订表格将从 mysql 数据库中获取数据。
比如说:
客户需要从第一个下拉列表中选择旅游,即(工业、文化、军事)。
选择旅游后,下一个下拉列表应列出目的地,即(英国、法国、德国等),具体取决于上述(旅游)选择。
然后第三个列表应显示取决于上述(目的地)选择的开始日期。
下拉列表中的所有数据都应来自数据库。此外,当客户提交表单时,所有这些数据都应进入数据库中的客户预订表。
有人告诉我 javascript 应该是答案,但我搜索了很多论坛并查看了所有令人困惑的教程。所以特地来这里问问!非常感谢有关如何执行此操作的任何帮助。谢谢!
以下是我只知道如何执行此操作的代码:
<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');
}
?>