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 "destination" of routes(Table Name) and "arrival"(from 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 : - <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>
8 1345
Hi Rose and welcome to Bytes.
First, please use the code tags to indicate posted code.
Looks like you were missing a bracket. -
<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>
-
<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'){
-
$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>
-
It happens....
It's usually the tiny details (either a bracket or semicolon).
Please mark the other post as the answer. Thank you.
- <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>
DROP DOWN LIST CODE - <!DOCTYPE>
-
<html>
-
<head>
-
<title>Update Data</title>
-
</head>
-
<body>
-
<form name="form_update" method="post" action="update_test.php">
-
<?php
-
$con=mysqli_connect("localhost","root","","ismat_db");
-
//============== check connection
-
if(mysqli_errno($con))
-
{
-
echo "Can't Connect to mySQL:".mysqli_connect_error();
-
}
-
else
-
{
-
echo "Connected to mySQL</br>";
-
}
-
//=============================
-
//This creates the drop down box
-
echo "<select name= 'FirstName'>";
-
echo '<option value="">'.'--- Please Select Person ---'.'</option>';
-
//$query=mysqli_query($con,"SELECT id,FirstName FROM persons");
-
$query = mysqli_query($con,"SELECT FirstName FROM persons");
-
$query_display = mysqli_query($con,"SELECT * FROM persons");
-
while($row=mysqli_fetch_array($query))
-
{
-
echo "<option value='". $row['id']."'>".$row['FirstName']
-
.'</option>';
-
}
-
echo '</select>';
-
?> <input type="submit" name="submit" value="Submit"/>
-
</form>
-
<br/><br/>
-
<a href="main.html"> Go back to Main Page </a>
-
</body>
-
</html>
Display View CodE - <!DOCTYPE>
-
<html>
-
<head>
-
<title>Update Data</title>
-
</head>
-
<body>
-
<!--<table>
-
<tr>
-
<td align="center"> From Database </td>
-
</tr>
-
<tr>
-
<td>
-
<table border="1">
-
<tr>
-
<td>First Name</td>
-
<td>Last Name </td>
-
<td> Gender </td>
-
<td> Subject </td>
-
<td> Hobbies </td>
-
</tr>
-
-->
-
<?php
-
$con=mysqli_connect("localhost","root","","ismat_db");
-
if(mysqli_errno($con))
-
{
-
echo "Can't Connect to mySQL:".mysqli_connect_error();
-
}
-
//$name = mysqli_real_escape_string($con,$_POST['select']);
-
// $fetch = mysqli_query($con,"SELECT * FROM persons WHERE FirstName='".$name."'");
-
// $row_display=mysqli_fetch_assoc($fetch);
-
if(isset($_POST['FirstName']))
-
{
-
$name = $_POST['FirstName'];
-
//$name = mysqli_real_escape_string($con,$_POST['select']);
-
//$fetch = "SELECT * FROM persons WHERE FirstName = '".$name."'";
-
//$fetch="SELECT 'Firstname' FROM persons WHERE Firstname = '".$name."'";
-
$fetch="SELECT Firstname FROM persons WHERE Firstname = '".$name."'";
-
$result = mysqli_query($con,$fetch);
-
if(!$result)
-
{
-
echo "Error:".(mysqli_error($con));
-
}
-
//display the table
-
echo '<table border="1">'.'<tr>'.'<td align="center">'. 'From Database'. '</td>'.'</tr>';
-
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'<td>'.'First Name'.'</td>'.'<td>'.'Last Name'.'</td>'.'<td>'. 'Gender' .'</td>'.'<td>'. 'Subject'. '</td>'.'<td>'. 'Hobbies' .'</td>'.'</tr>';
-
//while($data = mysqli_fetch_row($fetch))
-
while($data=mysqli_fetch_row($result))
-
{
-
echo ("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td><td>$data[4]</td></tr>");
-
}
-
echo '</table>'.'</td>'.'</tr>'.'</table>';
-
}
-
?>
-
<!--</table>
-
</td>
-
</tr>
-
</table>-->
-
<br/>
-
<a href="update.php"> Go back to Main Page </a>
-
</body>
-
</html>
Here data is fetch from same table ......but i want to fetch data from another table......based on FIRSTNAME selected.....
Please use code tags.
Try changing the table name?
FYI: -
mysql_query("select* from persons where firstname='$firstname'");
-
would get you all the data from persons based on the first name.
Also, for the possible future, please make the additional questions separate threads.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dec |
last post by:
Ok to simplify things I'll just give an example.
This is pretty much what I want to do (minus the postcode):
http://www.perrys.co.uk/usedcar?ID=F5J9BNNBMVK00DF
I have relatively little...
|
by: ramesh |
last post by:
hi,
I am using Com+ in my application. It will have
InsertRecords,selectRecords,updateRecords function.
In the Web Form i have Drop-down list. I want to select
records from SQL and add it to this...
|
by: Seelan |
last post by:
Hello folks,
I have a database table with CategoryID, Name and Description. I
made 2 DropDown Lists one for Displaying Name and the other for
Description. I want to add a web control, lets say a...
|
by: Leszek Taratuta |
last post by:
Hello,
I have several drop-down lists on my ASP.NET page. I need to keep data
sources of these lists in Session State.
What would be the most effective method to serialize this kind of data...
|
by: Eric Dan |
last post by:
Hi,
Even tough I was able to implement what I want in a weird and non efficient
way, I would like to get an opinion what is the right way to achieve my task:
Scenario:
• Display a DataGrid...
|
by: Vigneshwar Pilli via DotNetMonster.com |
last post by:
string connectionString1 = "server=(local); user=sa;password=sa;
database=sonic";
System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionString1);...
|
by: weiwei |
last post by:
Hi
here is my scenario, I create a drop down list in itemtemplate.(that
drop down is created from db), after user
click edit command, my ideal plan is have another drop down list in...
|
by: yogeshtiwarijbp |
last post by:
when i select data from the drop down list box and display data in the datagrid
the first data in the dropdownlistbox not shown the requireddata in the grid. i have used 2 tables and after selecting...
|
by: silwar |
last post by:
Hi,
I have already stored value of author id in list item value while page loads. but when I change index of drop down list to view author information error is shown. I tried to debug using check...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |