I'm trying hard with displaying details from a selected option in a drop down list for my project.
I have a two dropdown list which is populated from a MYSQLi query. I want the user to select an option from two drop down list and the values associated pulled from the database table and displayed to the user.
The dynamically populated drop down list is for "destinatio n" of routes(Table Name) and "arrival"(f rom routea table) when a user selects a destination and arrival from the drop down list I want the record of that another table(schedule) to be to be displayed.
The code below is for dynamically populating the drop down list. The user clicks the button and goes on the next page which should create a table with the results. There is Error in my code......plz check this
Choose Deparature :
I have a two dropdown list which is populated from a MYSQLi query. I want the user to select an option from two drop down list and the values associated pulled from the database table and displayed to the user.
The dynamically populated drop down list is for "destinatio n" of routes(Table Name) and "arrival"(f rom routea table) when a user selects a destination and arrival from the drop down list I want the record of that another table(schedule) to be to be displayed.
The code below is for dynamically populating the drop down list. The user clicks the button and goes on the next page which should create a table with the results. There is Error in my code......plz check this
Choose Deparature :
Code:
<form action="" method="POST">
<p>
<select name="departure">
<option value="" selected="selected">-- Choose destination --</option>
<option value="ABBOTTABAD">ABBOTTABAD</option>
<option value="AHMED PUR EAST">AHMED PUR EAST</option>
<option value="CHINIOT">CHINIOT</option>
<option value="DASKA">DASKA</option>
</select>
</p>
<p>Choose Arrival: </p>
<p>
<!--<form action="" method="POST"> -->
<select name="arrival">
<option value="" selected="selected">-- Choose Arrival --</option>
<option value="DASKA">DASKA</option>
<option value="CHINIOT">CHINIOT</option>
<option value="AHMED PUR EAST">AHMED PUR EAST</option>
<option value="ABBOTTABAD">ABBOTTABAD</option>
<option value="LAHORE">LAHORE</option>
</select>
</p>
<p> </br>
<input name="submit" type="submit" value="Submit" />
</p>
</form>
<table width="754" border="1" id="table">
<tr><th bgcolor="#00CCCC">Departure</th>
<th bgcolor="#00CCCC">Arrival</th>
<th bgcolor="#00CCCC">Departure time</th>
<th bgcolor="#00CCCC">Arrival time</th>
<th bgcolor="#00CCCC">Fare</th>
<th bgcolor="#00CCCC">Bus type</th>
<th bgcolor="#00CCCC">Total seats</th>
<th bgcolor="#00CCCC">Status</th>
</tr>
<?php
mysql_connect('localhost','root',"") or die('Error1 '.mysql_error());
mysql_select_db("bus_reservation1 (1)") or die('error2'.mysql_error());
if($_SERVER['REQUEST_METHOD'] =='POST')
//if(isset($_POST['Submit']))
{
$dep=$_POST['departure'];
$loc=$_POST['arrival'];
$query="SELECT * FROM schedule WHERE Departure= '" . $dep . "' AND Arrival= '".$loc."' ";
$run=mysql_query($query);
$numrow = mysql_num_rows($run);
while($row=mysql_fetch_array($run)){
echo "<tr>
<td bgcolor='#87a310'>".$row['Departure']."</td>
<td bgcolor='#87a310'>".$row['Arrival']."</td>
<td bgcolor='#87a310'>".$row['Departure_time']."</td>
<td bgcolor='#87a310'>".$row['Arrival_time']."</td>
<td bgcolor='#87a310'>".$row['Fare']."</td>
<td bgcolor='#87a310'>".$row['Bus_type']."</td>
<td bgcolor='#87a310'>".$row['Total Seats']."</td>
<td bgcolor='#87a310'>".$row['Status']."</td>
</tr>";
}
}
?>
</table>
Comment