我嘗試從MySQL過濾數據使用下拉選項在PHP
顯示的下拉菜單選項的一些數據,當用戶選擇選擇美國,然後點擊提交顯示,該頁面將進入下一個頁面,並顯示數據僅適用於美國
這裏是我的test.html
<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>
代碼在這裏是我的第二頁showDB.php
<?php
//connect to server
$connect = mysql_connect("localhost", "root", "");
//connect to database
mysql_select_db("asdasd");
//query the database
//$query = mysql_query("SELECT * FROM auip_wipo_sample");
if($_POST['value'] == 'US') {
// query to get all US records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE app_country='US'");
}
elseif($_POST['value'] == 'AUD') {
// query to get all AUD records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE app_country='AUD'");
} else {
// query to get all records
$query = mysql_query("SELECT * FROM auip_wipo_sample");
}
//fetch the result
Print "<table border cellpadding=3>";
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$row['invention_title'] . "</td> ";
Print "<th>Pet:</th> <td>".$row['invention-title'] . " </td></tr>";
}
Print "</table>";
?>
我嘗試上面的代碼,但我得到2錯誤其是
Undefined index: value in C:\xampp\htdocs\folder\showDB.php on line 10
Undefined index: value in C:\xampp\htdocs\folder\showDB.php on line 14
線10是 如果($ _ POST [ '值'] == 'US'){
和線14是 ELSEIF($ _ POST [ '值'] == 'AUD'){
誰能給溶液
感謝
感謝您的更正 我試過代碼,但我得到了一個錯誤在同一行「未定義的指數:國家」 – 2013-04-08 13:32:13
你能標記這是公認的答案嗎? – drewwyatt 2013-04-09 03:40:42
如果你真的硬編碼每個字符串?也許查詢應該看起來像'... WHERE app_country =「。$ _POST ['country'];' – George 2016-06-13 21:17:35