-1

我正在从数据库中获取类别及其子类别。并在使用下拉列表选择类别 bu 后过滤子类别。在我提交表单时选择后,子类别的值为0,表单不发布所选值。

<?php 
    if(isset($_POST) && $_POST['submit'] == "Add")
    {
        extract($_POST);
        $scat_id = $regions['scat_id'];
        echo $sqlpa = "INSERT INTO products(mcat_id, scat_id)VALUES('$mcat_id', '$scat_id')";   
            $resultpa = mysql_query($sqlpa);

    }
  ?>
<script type="text/javascript">
    function getregions(mcat_id) {
      if (mcat_id=="") {
         document.getElementById("region").innerHTML="";
         return;
      }
      if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp=new XMLHttpRequest();
      } else {// code for IE6, IE5
         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
           document.getElementById("region").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","getregions.php?mcat_id="+mcat_id,true);
    xmlhttp.send();
    }
    </script>
    <form action="" method="post" name="p_add" id="p_add">
     <table>        
      <tr>
         <td>Select Category</td>
         <td><select name="mcat_id" id="mcat_id" onchange="getregions(this.value);">
                <option value="">Select</option>
                 <?php 
              if(!empty($resultm)) {
                 foreach($resultm as $rm) {
             ?>
                <option value="<?php echo $rm['mcat_id']; ?>"><?php echo $rm['mcat_name'];?> (<?php echo $rm['mcat_id']; ?>)</option>
                 <?php 
                         }
                      }
                 ?>
           </select>
           </td>
         </tr>
         <tr>
           <td>Select Sub-Category</td>
           <td>
             <div id="region">
           <select name="scat_id" id="scat_id">
             <option value="">Please Select</option>
           </select>
         </div>
           </td>
         </tr>
         <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="submit" value="Add" /></td>
         </tr>       
   </table>
 </form>

-->这个页面是getregions.php,过滤完成的地方:

<?php 
   include "../conn.php";
   $mcat_id=$_GET['mcat_id'];
   $sql = "SELECT * FROM sub_category WHERE mcat_id = '".$mcat_id."'";
   $res = mysql_query($sql);
   while($row = mysql_fetch_array($res)) {
    $rec[] = $row ;
   }
?>
<select name="scat_id" id="scat_id">
    <option value="">Please Select</option>
<?php 
foreach($rec as $regions) {
?>
   <option value="<?php echo $regions['scat_id'];?>"><?php echo $regions['scat_name'];?></option>
<?php 
}
?>
</select>
4

1 回答 1

-2

就在插入查询之前,我需要写

 $scat_id = $_post['scat_id'];

这将获得发布的价值。

于 2012-10-08T08:41:14.760 回答