在选择下拉值时,我无法在重载功能上使用self.location传递并获取变量。
我只获得了第一个通过url传递的值,如何通过此samr url dd-mysqli.php传递第二个下拉列表中的值
@$cat=$_GET['cat'];
@$subcat=$_GET['subcat'];// 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;
}
?>
<?php
if(isset($_POST['submit'])){
$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
echo "Value of \$cat = $cat <br>Value of \$subcat = $subcat ";}
?>
<html>
<head>
<title>Multiple drop down list box from plus2net</title>
<SCRIPT language=JavaScript>
<!--
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;
self.location='dd-mysqli.php?cat=' + val + '&subcat=' + val2;
}
//-->
</script>
echo "<form method=post name=f1 action='dd-mysqli.php'>";
////////// Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
if($stmt = $connection->query("$query2")){
while ($row2 = $stmt->fetch_assoc()) {
if($row2['id']==@$cat){echo "<option selected value='$row2[id]'>$row2[category_description]</option>";}
else{echo "<option value='$row2[id]'>$row2[category_description]</option>";}
}
}else{
echo $connection->error;
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
echo "<select name='subcat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
if(isset($cat) and strlen($cat) > 0){
if($stmt = $connection->prepare("SELECT * FROM category AS c INNER JOIN category_language AS cl ON c.id=cl.category_id where parent_id=? && lang_id='1' ORDER BY category_description")){
$stmt->bind_param('i',$cat);
$stmt->execute();
$result = $stmt->get_result();
while ($row1 = $result->fetch_assoc()) {
if($row1['id']==@subcat){echo "<option selected value='$row1[id]'>$row1[category_description]</option>";}
else{echo "<option value='$row1[id]'>$row1[category_description]</option>";}
}
}
我该如何解决这个问题