下拉选择消息缺少PHP

时间:2017-03-25 16:30:04

标签: php mysqli

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

 <?php
    include "..\subjects\connect3.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>";
}



    ?>

1 个答案:

答案 0 :(得分:0)

更改此行

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

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

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

你使用$ row而不是$ value