Php 链接选择下拉列表

Php 链接选择下拉列表,php,html,Php,Html,我试着这么做:当有人从名为“主题”的下拉列表中选择任何选项时,“部分”下拉列表应该显示该主题的所有部分。“主题”下拉列表运行良好,可以获取所有主题的名称,但其中一个部分不起作用。我找不到问题所在。它应该在namedatabase列等于所选主题的位置/时间从数据库中获取节。提前谢谢。我的代码如下: 我的js代码 <script type="text/javascript"> function getSection(strURL) { alert(strURL);

我试着这么做:当有人从名为“主题”的下拉列表中选择任何选项时,“部分”下拉列表应该显示该主题的所有部分。“主题”下拉列表运行良好,可以获取所有主题的名称,但其中一个部分不起作用。我找不到问题所在。它应该在namedatabase列等于所选主题的位置/时间从数据库中获取节。提前谢谢。我的代码如下:

我的js代码

    <script type="text/javascript">
function getSection(strURL)
{      
alert(strURL);   
 var req = getXMLHTTP(); // fuction to get xmlhttp object
 if (req)
 {
  req.onreadystatechange = function()
 {
  if (req.readyState == 4) { //data is retrieved from server
   if (req.status == 200) { // which reprents ok status                    
     document.getElementById('sectiondiv').innerHTML=req.responseText;
  }
  else
  { 
     alert("There was a problem while using XMLHTTP:\n");
  }
  }            
  }        
req.open("GET", strURL, true); //open url using get method
req.send(null);
 }
}
</script>
php代码:

<div>
            Subject:

    <?php

    $conn = new mysqli('localhost', '', '', '') 
    or die ('Cannot connect to db');

        $result = $conn->query("select name from class");


        echo "<select name='subject' onchange='getSection('findsection.php?subject=>'this.value'";

        while ($row = $result->fetch_assoc()) {

                      unset($id, $name);
                      $name = $row['name']; 
                      echo '<option value="subject">'.$name.'</option>';

    }

        echo "</select>";
    ?> 
            </div>
    <br>  
    <div id="sectiondiv">
    Section: 
        <select name="select">
     </select>
            </div>
my findsection.php

<? $subject=intval($_GET[‘subject’]);;
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$mysqli  = new Mysqli($servername, $username, $password, $dbname) or mysqli_error($mysqli);
$section = $mysqli->query("SELECT section FROM class WHERE name = '$subject'")->fetch_object()->section; 
$result=mysql_query($section);?>
<select name="section">
<? while ($row = $result->fetch_assoc()) { ?>
   <option value><?=$row['section']?></option>
<? } ?>
</select>

您的html不完整/无效

echo "<select name='subject' onchange='getSection('findsection.php?subject=>'this.value'";
换成这个

echo '<select name="subject" onchange="getSection(\'findsection.php?subject=\' + this.value)">';

这使得它显示一个弹出窗口,显示findsection.php?subject=subject only?我真的无法解决这个问题一个星期现在idk为什么。