title: Inserting selected value from populated mysql dropdown
body: <p>I am trying to insert the selected value from a drop down that was populated from a reference table in my database. I followed a tutorial for a dynamic dropdown but now I would like to take the value and insert it. The problem is it keeps taking the echo the tutorial uses. Is there a way I can make that selected value a new variable? It currently inserts "&lt; php echo $team_name"</p>
  
  <pre><code>&lt;div&gt;
      &lt;label&gt;Home Team&lt;/label&gt;
      &lt;select name="home_team" style="width:125px;&gt;
          &lt;option value=""&gt;Select Team&lt;/option&gt;
          &lt;?php
              $query = "SELECT * FROM team";
              $results = mysqli_query($db, $query);
              mysqli_query($db, "SELECT * FROM team_name");
              // loop
              foreach ($results as $team_name) {
          ?&gt;
          &lt;option value="&lt;php echo $team_name["cid"]; ?&gt;&lt;?php echo $team_name["team_name"]; ?&gt;&lt;/option&gt;
          &lt;?php
          }
          ?&gt;
     &lt;/select&gt;
  </code></pre>
  
  <p>How I attempted to insert:</p>
  
  <pre><code>$db = mysqli_connect('localhost', 'root', 'root', 'register');
  if(mysqli_connect_errno())
  {
      echo "failed" . mysqli_connect_error();
  }
  //var_dump($_POST);
  $home_team = mysqli_real_escape_string($db, $_POST['home_team']);
  $home_team = $home_team;
  $query = "INSERT INTO game_table (home_team)
            VALUES('$home_team')";
  mysqli_query($db, $query);
  //echo $query;
  //echo $home_team;
  //header('location: index.php');
  </code></pre>