我正在尝试获取下拉菜单的选定值并将其存储在变量中,但我收到的是“索引未定义”错误。
我希望能够从下拉菜单中获取数据,并根据所选值将数据推送到表中。
<form id='dropdownform' method='post' name='dropdownform'>
**<select name='dropdownlist' id='dropdownlist'>**
<option value=''> --All Years-- </option>
<?php
$connection = mysqli_connect("localhost", "root", "");
mysqli_select_db($connection,"6nationsDB");
$dropdownlist = mysqli_query($connection, "SELECT * FROM results GROUP BY year");
while($row = mysqli_fetch_array($dropdownlist)) {
print("<option value='" . $row[year] . "'>" . $row[year] . "</option>");
}
?>
</form>
<?php
print("</select>");
print("</form>");
print('<table>');
print('<tr>');
print('<th>Round</th>');
print('<th>Date</th>');
print('<th></th>');
print('<th>Home Team</th>');
print('<th></th>');
print('<th></th>');
print('<th></th>');
print('<th>Away Team</th>');
print('<th></th>');
print('<th>Venue</th>');
print('</tr>');
**$select_val = $_POST['dropdownlist'];**
if($select_val == '') {
$resultset = mysqli_query($connection, "SELECT * FROM results ORDER BY rnd, date");
}
else {
while ($row=mysqli_fetch_array($resultset)) {
print('<tr>');
print('<td>' . $row['rnd'] . '</td>');
print('<td>' . $row['date'] . '</td>');
$homeTeamResults = mysqli_query($connection, "select * from teams where id = " . $row['HomeTeamID']);
$row2 = mysqli_fetch_array($homeTeamResults);
print('<td>' . "<img src='images/" . $row['HomeTeamID'] . ".png' height='15px'>" . '</td>');
print('<td>' . $row2['name'] . '</td>');
print('<td>' . $row['HomeTeamScore'] . '</td>');
print('<td>-</td>');
print('<td>' . $row['AwayTeamScore'] . '</td>');
$awayTeamResults = mysqli_query($connection, "select * from teams where id = " . $row['AwayTeamID']);
$row3 = mysqli_fetch_array($awayTeamResults);
print('<td>' . $row3['name'] . '</td>');
print('<td>' . "<img src='images/" . $row['AwayTeamID'] . ".png' height='15px'>" . '</td>');
print('<td>' . $row['venue'] . '</td>');
}
}
print('</table>');
?>[![this is the error message][1]][1]
任何和所有的帮助将不胜感激,我是PHP的新手