2

mySQL のドロップダウン オプションでいくつかのデータを表示しようとしています

ユーザーがオプション [米国] を選択して [送信] をクリックすると、ページは次のページに移動し、米国のデータのみが表示されます。

これが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>

ここに私の2番目のページ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行目は if($_POST['value'] == 'US') {

14行目はelseif($_POST['value'] == 'AUD') {

誰でも解決策を与えることができます

ありがとう

4

2 に答える 2

1

フォームに名前の要素がvalueないため、どちらもありません$_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>
于 2013-04-07T15:45:27.187 に答える