<tr>
<td>Crew Name:</td>
<td><input type="text" name="CrewName" id ="CrewName"required></td>
</tr>
<tr>
<td>Crew Rank:</td>
<td>
<input type="hidden" name="CrewRank" id="CrewRank" required>
<select>
<?php
$con = getDbConnect();
if (!mysqli_connect_errno($con)) {
$queryStr = "SELECT rank "."FROM rankpage";
}
$result = mysqli_query($con, $queryStr);
while ($row = mysqli_fetch_array($result)) {
echo "<option>" . $row['rank'] . "</option>";
}
?>
</select>
</input>
</td>
</tr>
当我尝试为输入表单使用下拉列表选项时,我可以显示下拉列表,但所选结果不会进入数据库。我不确定如何将我的选择选项链接为输入类型或将ID链接到我选择的结果
答案 0 :(得分:1)
检查选项标签的value属性。您需要将值设置为POST。
应该是这样的:
echo "<option value=\"" . $row['rank'] . "\">" . $row['rank'] . "</option>";
并将name
属性(例如rank
)传递给select
代码。您应该获得$_REQUEST['rank']
中的值。您可以使用$_GET
或$_POST
,具体取决于<form>
答案 1 :(得分:1)
您不需要链接选择选项作为输入类型。您只需要为select元素添加名称,并将选项元素的值添加为:
<tr>
<td>Crew Name:</td>
<td>
<input type="text" name="CrewName" id ="CrewName" required />
</td>
</tr>
<tr>
<td>Crew Rank:</td>
<td>
<select name="CrewRank" id="CrewRank">
<?php
$con = getDbConnect();
if (!mysqli_connect_errno($con)) {
$queryStr = "SELECT rank " .
"FROM rankpage";
}
$result = mysqli_query($con, $queryStr);
while ($row = mysqli_fetch_array($result)) {
echo "<option value=\"" . $row['rank'] . "\">" . $row['rank'] . "</option>";
}
?>
</select>
</td>
</tr>