title: How can I get the selected value from a drop down list
body: <p>I am trying to use a dynamically generated dropdown list to populate a table. I have a drop down list that is generated from my database (it grabs all the years available for a specific player). I want to be able to select a year from the dropdown and have it update my table. I have the dropdown being generated, but I am not able to get the selected value from the dropdown. I have code below that I found here, but it doesn't seem to work. Here is the code I have so far:</p>
  
  <pre><code>&lt;input name="update" type="submit" value="Update" /&gt;
  &lt;/form&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;form  action="player_login.html"&gt;
  &lt;input type="submit" value="Logout" /&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;div style="float: left"&gt;
      &lt;p&gt;&lt;/p&gt;
  &lt;h1&gt;Player Stats&lt;/h1&gt;
  &lt;table width="300" border="1" cellpadding="2" cellspacing="2"&gt;
  
  &lt;?php
      // get "id" field from player table
      $login_id = $_COOKIE["DB"];
      $id = "select id from player where login_id='$login_id';";
      $result1=mysql_query($id)  or die('Select1 Query failed: ' . mysql_error());
      $row = mysql_fetch_array($result1);
  
      // create a dropdown from stats table in db
      echo "--Select Year--";
          $years_query = "select year from stats where player_id='$row[id]';";
          $years = mysql_query($years_query, $connect);
  
          // fill array with db info
          $var = array();
          while ($row2 = mysql_fetch_array($years))
          {
              $var[] = $row2['year'];
          }
  
          // create dropdown
      echo'&lt;select name="years" id="years"&gt;'; 
      // For each value of the array assign variable name "city" 
      foreach($var as $year)
      { 
              echo'&lt;option value="'.$year.'"&gt;'.$year.'&lt;/option&gt;'; 
      }    
      echo'&lt;/select&gt;';
  
      // get selected option from dropdown
      $selected_key = $_POST['years'];
      $selected_val = $var[$_POST['years']];
      echo "&lt;p&gt;&lt;/p&gt;selected key: " . $selected_val; // this wont print anything???
  
      $search_query="select * from stats where player_id='$row[id]' and year=2013;";
      $result=mysql_query($search_query)  or die('Select2 Query failed: ' . mysql_error());
      $num_cols = mysql_num_fields($result);
      $line = mysql_fetch_row($result);
  
      // create table with results
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;Year&lt;/td&gt;";  
          $j=1;
          echo "&lt;td&gt;&lt;input name='$j' type='text' value='$line[$j]' size=20/&gt;&lt;/td&gt;";
      echo "&lt;/tr&gt;";
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;Total Points&lt;/td&gt;";  
          $j=2;
          echo "&lt;td&gt;&lt;input name='$j' type='text' value='$line[$j]' size=20/&gt;&lt;/td&gt;";
      echo "&lt;/tr&gt;";
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;PPG&lt;/td&gt;";  
          $j=3;
          echo "&lt;td&gt;&lt;input name='$j' type='text' value='$line[$j]' size=20/&gt;&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  
  
  ?&gt; 
  
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>