Drop down menu unable to post data selected on submit in php, the coding returns the category id number not the data in category after selection. I need the data to be posted in the next page not the id… how can i do that?
<?php
require 'config.php'; // Database connection
//////// End of connecting to database ////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Multiple drop down list box from plus2net</title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.category.options[form.category.options.selectedIndex].value;
self.location='dd.php?category=' + val ;
}
</script>
</head>
<body>
<?Php
@$cat=$_GET['category']; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not.
echo "Data Error";
exit;
}
///////// Getting the data from Mysql table for first list box//////////
$quer2="SELECT DISTINCT category,cat_id FROM category order by category";
///////////// 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/////
if(isset($cat) and strlen($cat) > 0){
$quer="SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory";
}
else
{$quer="SELECT DISTINCT subcategory FROM subcategory order by subcategory"; }
////////// end of query for second subcategory drop down list box ///////////////////////////
echo "<form method=post name=f1 action='dd-check.php'>";
/// Add your form processing page address to action in above line. Example action=check_page.php////
////////// Starting of first drop downlist /////////
echo "<select name='category' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
foreach ($dbo->query($quer2) as $noticia2) {
if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";}
else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo "<select name='subcategory'><option value=''>Select one</option>";
foreach ($dbo->query($quer) as $noticia)
{
echo "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
echo "<br>";
echo "<input type=submit value=Search>";
//for testing
echo "Value of \$cat1 = $cat";
echo "</form>";
?>
<br><br>
<a href=dd.php>Reset and start again</a>
</body>
</html>