在php中使用下拉选项筛选要显示的数据
我试图通过mySQL中的下拉选项显示一些数据 当用户选择“美国”选项并单击“提交”时,页面将转到下一页并仅显示美国的数据 这是我的test.html代码在php中使用下拉选项筛选要显示的数据,php,mysql,drop-down-menu,filter,Php,Mysql,Drop Down Menu,Filter,我试图通过mySQL中的下拉选项显示一些数据 当用户选择“美国”选项并单击“提交”时,页面将转到下一页并仅显示美国的数据 这是我的test.html代码 <body> <table border="0"> <tr> <th>test </th> </tr> <tr> <td>Select Foreign Agent Country&l
<body>
<table border="0">
<tr>
<th>test
</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select>
<option value="US">United States</option>
<option value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<button type="submit"><a href="showDB.php">submit</a></button>
</td>
</table>
</body>
第10行是
如果($_POST['value']=='US'){
第14行是
elseif($_POST['value']=='AUD'){
任何人都可以给出解决方案
谢谢您的表单中没有名为
value
的元素,因此您也没有$\u POST['value']
的表单!实际上,您甚至没有表单要提交,您只是在提交按钮内放置了一个指向另一页面的链接
<body>
<form action="showDB.php">
<table border="0">
<tr>
<th>test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="value">
<option value="US">United States</option>
<option value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<button type="submit">submit</button>
</td>
</table>
</form>
</body>
测试
选择国外代理国家/地区
美国
澳大利亚
提交
您需要在test.html中添加一个name
参数-或者将其设置为name=“value”
以使showDB.php在不做任何修改的情况下工作,或者将第10行和第14行设置为与您设置的name
参数匹配。下面的示例:
编辑:
@adeneo是对的,您还需要添加一个表单和一个有效的提交按钮
<body>
<form action="showDB.php" method="post">
<table border="0">
<tr>
<th>test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="value">
<option name="country" value="US">United States</option>
<option name="country" value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<input type="submit" name="btn_submit" />
</td>
</table>
</form>
</body>
感谢您的更正,我尝试了代码,但在同一行“Undefined index:country”中出现了一个错误。您真的应该对每个字符串进行硬编码吗?也许查询应该像
…WHERE app_country=“.$\u POST['country'”;
<body>
<form action="showDB.php">
<table border="0">
<tr>
<th>test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="value">
<option value="US">United States</option>
<option value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<button type="submit">submit</button>
</td>
</table>
</form>
</body>
<body>
<form action="showDB.php" method="post">
<table border="0">
<tr>
<th>test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="value">
<option name="country" value="US">United States</option>
<option name="country" value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<input type="submit" name="btn_submit" />
</td>
</table>
</form>
</body>
if($_POST['country'] == 'US') {
// query to get all US records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE app_country='US'");
}
elseif($_POST['country'] == 'AUD') {