Hi there,
I am trying to create a webpage that contains two buttons that would direct users to a different site, depending on which submit was selected. In addition, the 2nd submit has 2 options.
Ex: (some content edited for web purposes)
Let's say I wanted to find gas stations. My page would have:
1) A drop down that would contain "Exxon, Sunoco, etc." with a submit. This would take me to "$gasstation".php. I would have individual pages, like, exxon.php, sunoco.php. It would automatically go to this page when the button is clicked.
2) A dropdown for state, which would then populate a drop down for city. After the city is selected, the submit would take me to a page where I can populate different gasstations based on the state/county. This new page might have a section for Exxon, and then Citgo for state/county A, but for B it might be Citgo, then Gulf.
At this time, my dropdowns show the correct values, but I'm not passing them properly. There's a lot of borrowed code, and extra comments that were old code. I left this in, just in case I need it. In addition, I would like to avoid JavaScript, since I hear people turn this off. Thanks in advance.
I have included the code, below:
<html>
<head>
<title>New document</title>
</head>
<body>
<br />
<?php
$homepage='http://localhost/homes';
function redirect($url){
header("location:$url");
}
// Database Stuff
$dbservertype='mysql';
$servername='localhost';
// username and password to log onto db server
$dbusername='root';
$dbpassword='password';
// name of database
$dbname='dbname';
////////////////////////////////////////
////// DONOT EDIT BELOW /////////
///////////////////////////////////////
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
?>
<html>
<head>
<title>Multiple drop down list box from plus2net</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.state_id.options[form.state_id.options.selectedIndex].value;
self.location='TryingTheDropDown.php?state_id=' + val ;
}
</script>
</head>
<body>
<?
if (isset($_GET['btn1']))
{echo 'pressed button 1';
echo "var3[gasstation_name]=$var3[gasstation_name]";
echo "gasstation_id=$var3[gasstation_id]";
echo( "<a href=$gasstation_webpage<br></a>" );
exit;}
else if (isset($_GET['btn3']))
//button 3 is only temporary..replace this with btn2 when ready.
{echo 'pressed button 2';
echo "$var2[state_id].$var2[state_name]";
echo "$var2[state_name]";
echo "$var[county_name]";
$to=$homepage.'/state.php?state_id="$var2[state_name]".&.county_name=$var[county_name]"/';
?><META HTTP-EQUIV="Refresh" Content= "0; URL=<?php echo $to; ?>"><?php
exit;}
else if (isset($_GET['btn2']))
{echo 'pressed button 2';
echo "$var2[state_id].$var2[state_name]";
echo "$var2[state_name]";
echo "$var[county_name]";
exit;}
// action='state.php?state_id=$var2[state_name]&county_name=$var[county_name]'
///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT state_name,state_id FROM state order by state_name");
$query_gasstations=mysql_query("SELECT gasstation_name,gasstation_id,gasstation_webpage FROM gasstation");
$gasstation_id=$HTTP_GET_VARS['gasstation_id'];
//if(isset($gasstation_id) and strlen($gasstation_id) > 0){
//$query_gasstations=mysql_query("SELECT gasstation_name FROM gasstation ORDER by gasstation_id");}
//else {$query_gasstations=mysql_query("SELECT gasstation_name FROM gasstation ORDER by gasstation_id");}
echo "<form method=get name=btn1 >";
/// Add your form processing page address to action in above line. Example action=check.php////
////////// Starting of first drop downlist /////////
echo "<H4>Search by gasstation: <select name='gasstation_id'><option value=''>Select one</option></H4>";
while($var3 = mysql_fetch_array($query_gasstations)) {
if($var3['gasstation_id']==@$gasstation_id){echo "<option selected value='$var3[gasstation_id]'>$var3[gasstation_name]</option>"."<BR>";}
else{echo "<option value='$var3[gasstation_id]'>$var3[gasstation_name]</option>";}
}
echo "<input type=submit name=btn1 value=Submit>";
echo "<br>";
echo "<br>";
echo "</select>";
///////////// End of query for first list box////////////
/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
$state_id=$HTTP_GET_VARS['state_id']; // This line is added to take care if your global variable is off
if(isset($state_id) and strlen($state_id) > 0){
$quer=mysql_query("SELECT DISTINCT county_name
FROM county
JOIN countystate
ON county.county_id=countystate.county_id
WHERE state_id = $state_id
ORDER BY county_name
");
}else{$quer=mysql_query("SELECT DISTINCT county_name
FROM county
JOIN countystate
ON county.county_id=countystate.county_id
WHERE state_id =31
ORDER BY county_name
"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
// echo "<form method=get name=btn2 action='state.php?state_id=$var2[state_name]&county_name=$var[county_name]'>";
echo "<form method=get name=btn2 action='state.php?state_id=$var2[state_name]&county_name=$var[county_name]'>";
/// Add your form processing page address to action in above line. Example action=check.php////
////////// Starting of first drop downlist /////////
echo "<H4>Search by State: <select name='state_id' onchange=\"reload(this.form)\"><option value=''>Select one</option></H4>";
while($var2 = mysql_fetch_array($quer2)) {
if($var2['state_id']==@$state_id){echo "<option selected value='$var2[state_id]'>$var2[state_name]</option>"."<BR>";}
else{echo "<option value='$var2[state_id]'>$var2[state_name]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo " County: ";
echo "<select name='county_name'><option value=''>Select one</option>";
while($var = mysql_fetch_array($quer)) {
echo "<option value='$var[county_name]'>$var[county_name]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
echo "<input type=submit name=btn2 value=Submit>";
echo "</form>";
?>