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 に答える