下拉选择消息缺少 PHP

  • 本文关键字:PHP 消息 选择 php mysqli
  • 更新时间 :
  • 英文 :


所以我这里有这个代码,当我选择摄入下拉列表时,它应该在弹出消息中显示 ID,因为我添加了 alert((。但是,相反,它在消息中不显示任何内容。我的代码有问题吗?

 <?php
    include "..subjectsconnect3.php";
    //echo "Connection successs";
    $query = "SELECT * FROM programmes_list";
    $result = mysqli_query($link, $query);
    ?>
    <form name = "form1" action="" method=""post>
    <table>
    <tr>
    <td>Select Pragramme</td>
    <td><select id="programmedd" onChange="change_programme()">
    <option>select</option>
    <?php
    while($row=mysqli_fetch_array($result)){
        ?>
    <option value="<?php echo $row["ID"]; ?>"><?php echo $row["programme_name"]; ?></option>
    <?php
        }
        ?>
        </select></td>
        </tr>
        <tr>
            <td>Select intake</td>
            <td>
            <div id="intake">
            <select>
            <option>Select</option>
            </select>
            </div>
            </td>
        </tr>
        <tr>
            <td>Select Subjects</td>
            <td>
            <div id="subject">
            <select>
            <option>Select</option>
            </select>
            </div>
            </td>
        </tr>

    </table>
    </form>             
    <script type="text/javascript">
    function change_programme()
    {
        var xmlhttp=new XMLHttpRequest();
        xmlhttp.open("GET","ajax.php?programme="+document.getElementById("programmedd").value,false);
        xmlhttp.send(null);
        document.getElementById("intake").innerHTML=xmlhttp.responseText;
    }
    function change_intake(){
        alert(document.getElementById("intakedd").value);
    }
    </script>

//ajax.php
<?php
    $dbhost = 'localhost' ;
    $username = 'root' ;
    $password = '' ;
    $db = 'programmes' ;
    $link = mysqli_connect("$dbhost", "$username", "$password");
    mysqli_select_db($link, $db);
    $programme=$_GET["programme"];

if($programme!="")
{
    $res=mysqli_query($link, "select * from intakes where intake_no = $programme");
    echo "<select id='intakedd' onChange='change_intake()'>";
    while($value = mysqli_fetch_assoc($res))
    {
    echo "<option value='$row[ID]'>";
    echo $value["intake_list"];
    echo "</option>";
    }   
    echo "</select>";
}

    ?>

更改此行

 echo "<option value='$row[ID]'>"; TO 
    echo "<option value=$value['ID']>"; OR 
    echo "<option value=".$value['ID'].">";

你用了$row$value

最新更新