$sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'lab_db'";
$result = mysqli_query($db, $sql);
echo "<form action=\"insert_position.php\" method=\"GET\">";
echo "<select name=\"selected_pos\">";
while ($row = mysqli_fetch_array($result)) {
echo "<option >",$row['0'],"</option>";
}
echo "</select>";
echo "</form>";
if (isset($_GET['upload_table'])) {
$sel = $_GET['selected_pos'];
echo $sel;
}
?>
<form action="insert_position.php" method="GET">
<input name="upload_table" type="submit" value="Загрузить таблицу">
</form>
答案 0 :(得分:1)
默认情况下,提交按钮会提交它所在的表单。由于<select>
元素位于另一个<form>
内,因此单击提交按钮时将不会提交。
为了解决您的问题,只需将提交按钮添加到select元素所在的同一表单中。
以下是更正后的代码:
<?php
$sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'lab_db'";
$result = mysqli_query($db, $sql);
echo '<form action="insert_position.php" method="GET">';
echo '<select name="selected_pos">';
while ($row = mysqli_fetch_array($result))
{
echo "<option>".$row[0]."</option>";
}
echo "</select>";
if (isset($_GET['upload_table']))
{
$sel = $_GET['selected_pos'];
echo $sel;
}
?>
<input name="upload_table" type="submit" value="Загрузить таблицу">
</form>