我需要使用基本查询填充下拉列表但无法填写。我以前在事故中填充了它,但是我需要改变一些小的东西,并且滚雪球失控,我不能再产生一个填充的下拉列表了。
<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>
答案 0 :(得分: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>";
}
}