Php 有人能解释一下为什么我下面的代码不';当我按下提交按钮时,你不工作吗?
它不会从下拉菜单中显示所选年份-这正是我试图实现的。它打印到“你选择”,然后不打印年份。这就是我想展示的Php 有人能解释一下为什么我下面的代码不';当我按下提交按钮时,你不工作吗?,php,mysql,sql,Php,Mysql,Sql,它不会从下拉菜单中显示所选年份-这正是我试图实现的。它打印到“你选择”,然后不打印年份。这就是我想展示的 <html> <head><title> Hello </title> <?php //code for connection include 'connect.php'; ?> </head> <body> <center> <br> <b>welcome</
<html>
<head><title> Hello </title>
<?php
//code for connection
include 'connect.php';
?>
</head>
<body>
<center>
<br>
<b>welcome</b>
<br>
<?php
$sql1 = "SELECT DISTINCT Year FROM dbnames ORDER BY Year";
$runsql1 = mysql_query($sql1);
if (!$runsql1)
{
die( "Could not execute sql:" . mysql_error());
}
while($row = mysql_fetch_array($runsql1))
{
$options .="<option>".$row['Year']."</option>";
}
$years = "<form id='filter1' name='filter1' method='post' action=''>
<select name='filter2' id='filter2'>".$options."</select></form>";
echo "Please choose an year".$years;
?>
<!-- submit button -->
<p><input type="submit" value="Submit"></p>
<?php
echo 'You choose'. $_POST[filter2];
?>
</center>
</body>
</html>
你好
欢迎
尝试以下方法:
<?php
// Connect to DB
include 'connect.php';
// Load Select Options
$year_results = mysql_query("SELECT DISTINCT Year FROM dbnames ORDER BY Year ASC") or die(mysql_error());
$year_options = array();
while ($row = mysql_fetch_assoc($year_results)) {
$year_options[] = '<option value="'. $row['year'] .'">'. $row['year'] .'</option>';
}
// Handle Post/Selected Year
$selected_year = (!empty($_POST['filter2']) ? $_POST['filter2'] : 'No Year Selected');
?>
<html>
<head>
<title> Hello </title>
</head>
<body>
<center>
<br>
<b>welcome</b>
<br>
<form id='filter1' name='filter1' method='post' action=''>
Please choose an year: <select name='filter2' id='filter2'>
<?php echo implode("\r\n", $year_options) ?>
</select>
<input type="submit" value="Submit">
</form>
You choose: <?php echo $selected_year ?>
</center>
</body>
</html>
你好
欢迎
请选择一年:
您可以选择:
。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果选择PDO,.
将首先执行。-<代码>然后
然后
编辑:另外,正如Jonathan所说,您的提交不是表单的一部分。您的提交按钮不是表单的一部分。它必须位于
标记的内部,否则它只是一个按钮,不知道提交什么。@Fred ii-这是完成的顺序。他们在“.$options.”“
下面构建了一系列选项,除非我遗漏了什么。@Fred ii-事情就是这样,对吧?@itachi一个非常大的溢出lol