I'm trying to get the selected value of a dropdown menu and store it in a variable, but i'm getting an 'index undefined' error.
I want to be able to take the data taken from the dropdown menu and push the data to a table based on the selected value.
<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]
any and all help would be appreciated, I'm quite new to PHP