第三个下拉菜单不会从数据库中填充

时间:2014-04-29 10:58:09

标签: php jquery mysql ajax

我有以下Index.php:

<script language="javascript" type="text/javascript">

function getXMLHTTP() { //function to return the xml http object
        var xmlhttp=false;  
        try{
            xmlhttp=new XMLHttpRequest();
        }
        catch(e)    {       
            try{            
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e1){
                    xmlhttp=false;
                }
            }
        }

        return xmlhttp;
    }

    function getColor(CategoryId) {     

        var strURL="getColor.php?Category="+CategoryId;
        var req = getXMLHTTP();

        if (req) {

            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                    if (req.status == 200) {                        
                        document.getElementById('qcolor').innerHTML=req.responseText;                       
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }               
            }           
            req.open("GET", strURL, true);
            req.send(null);
        }       
    }
    function getBrand(CategoryId,ColorId) {     
        var strURL="getBrand.php?Category="+CategoryId+"&Color="+ColorId;
        var req = getXMLHTTP();

        if (req) {

            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                    if (req.status == 200) {                        
                        document.getElementById('qbrand').innerHTML=req.responseText;                       
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }               
            }           
            req.open("GET", strURL, true);
            req.send(null);
        }

    }
</script>
</head>
<body>
<div id="Quick_find_2">
         <div id="Quick_find_container">
           <form action="search2.php" method="get">
             <div id="qcategory_1">Product</div>
             <div id="qcategory">
               <select name="Category" class="dropmenu" id="Category" onChange="getColor(this.value)">
                 <option value="">Any</option>
                 <option value="Keyboard">Keyboard</option>
                 <option value="Piano">Piano</option>
               </select>
             </div>

             <div id="qcolor_1">Colour</div>
             <div id="qcolor"><select name="Color" id="Color" class="dropmenu">
    <option value="">Select Color</option>
        </select>

             </div>
             <div id="qbrand_1">Brand</div>
             <div id="qbrand"><select name="Manufacturer" class="dropmenu">
                 <option value="">Any</option> </select>

             </div>

请注意表单尚未就绪,但最后需要提交按钮,但是现在我只想填充下拉菜单 前两个菜单工作正常,我在填写最后一个菜单时遇到了麻烦。 getColor.php包含以下代码:

$Category= $_GET['Category'];
mysql_select_db($database_dconn, $dconn);
    $query="SELECT DISTINCT Color FROM products WHERE products.Category LIKE '%$Category%'  AND Category!= 'Stage Pianos' AND Category!= 'Recent Pianos' AND Category!= 'Recent Keyboards' AND hidden ='no' ORDER BY Color";
    $result=mysql_query($query);

    ?>
    <select name="Color" onchange="getBrand(<?=$Category?>,this.value)">
    <option value="">Select Color</option>
    <? while($row=mysql_fetch_array($result)) { ?>
    <option value=<?=$row['Color']?>><?=$row['Color']?></option>
    <? } ?>
    </select>

getBrand.php包含以下代码:

$Category=$_GET['Category'];
$Color=$_GET['Color'];

mysql_select_db($database_dconn, $dconn);
$query="SELECT DISTINCT Manufacturer FROM products WHERE products.Category LIKE '%$Category%' AND Color = '$Color' AND Category!= 'Stage Pianos' AND Category!= 'Recent Pianos' AND Category!= 'Recent Keyboards' AND hidden ='no' ORDER BY Manufacturer";
$result=mysql_query($query);


?>
<select name="Manufacturer">
<option value="">Select Brand</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value="<?=$row['Manufacturer']?>"><?=$row['Manufacturer']?></option>
<? } ?>
</select>

请不要担心SQL注入,因为我会对它进行排序。

以某种方式,$ Category和Color的值没有被传递到任何人都可以看到我出错的地方?欢迎任何帮助

0 个答案:

没有答案