1

我需要使用基本查询填充下拉列表,但无法。我之前意外填充了它,但我需要更改一些小的东西,它滚雪球失控,我无法再产生填充的下拉列表。

<html>
    <ul id="navigation">
        <li><a href="index.php">Home</a></li>
        <li><a href="view.php">Available Content</a></li>
        <li><a href="topic.php">Topics</a></li>
        <li><a href="login.php">Login</a></li>
        <li><a href="sign_up.php">Sign-Up</a></li>
        <li><a href="logout.php">Logout</a></li>
    </ul> 


    <form method="post" action="topicChosen.php">
        <select name="selectitem">
            <?php
            require_once 'needed.php';
            if (isset($_SESSION["p_id"])) {
                if ($stmt = $mysqli->prepare("Select distinct topic from topic")) {
                    $stmt->execute();
                    $stmt->bind_result($var1);
                    while ($stmt->fetch()) {
                        echo "<option value=\"$var1\">$var1</option>";
                    }
                }
            } else {
                //if user not logged in
            }
            ?>
        </select>
        <input type="submit" value="send">
    </form>




</html>

桌子

4

1 回答 1

0

您不检查 MySQL 调用的返回值。添加至少or die($mysqli->error)以查看发生了什么问题

$stmt = $mysqli->prepare("Select distinct topic from topic") or die($mysqli->error);
if ($stmt) {
    $stmt->execute() or die($stmt->error);
    $stmt->bind_result($var1) or die($stmt->error);
    while ($stmt->fetch() or die($stmt->error)) {
        echo "<option value=\"$var1\">$var1</option>";
    }
}
于 2013-04-13T21:15:35.460 回答