I have created the following page which populates a dropdown menu with a value form a database. However I would like it so that once I have selected a value and clicked submit the location_ID is passed over to the results page so that I can then do further queries depending on what the user has requested.
However I am really struggling to do this and would be grateful for some advice.
Cheers
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$dbcnx = @mysql_connect("localhost", "root", "sj198024");
if (!$dbcnx) {
echo( "<P>Unable to connect to the database server at this time.</P>" );
exit();
}
if (!@mysql_select_db("tpvhc", $dbcnx) ) {
echo( "<P>Unable to locate the Correct database at this time.</P>" );
exit();
}
$location="SELECT Location_ID, Location From Location Order BY Location";
//Run query;
$result=@mysql_query($location);
//Lets create the select
?>
<form action="quicksearchresults.php" method="get" class="forms">
<select>
<?php
//Lets loop through the colors (only if there are some)
if(mysql_num_rows($result)==0){
}else{
while($row=mysql_fetch_array($result)){
?>
<option value="<?php echo($row['Location_ID']); ?>"><?php echo($row['Location']);
?> </option>
<?php
}
}
?>
</select>
<input type="submit" class="submit">
</body>
</html>
results Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$location = ($_GET['location_ID']);
$dbcnx = @mysql_connect("localhost", "root", "sj198024");
if (!$dbcnx) {
echo( "<P>Unable to connect to the database server at this time.</P>" );
exit();
}
if (!@mysql_select_db("tpvhc", $dbcnx) ) {
echo( "<P>Unable to locate the Correct database at this time.</P>" );
exit();
}
$result = mysql_query("SELECT * From Cottage Where Location = $location ");
while($row = mysql_fetch_assoc($result)){
echo "Name:".$row['name'] .", Owner:".$row['owner'].", Species:".$row['species']."<br/>";
}
?>
</body>
</html>