title: How to pass the selected value in dropdown (HTML) to PHP
body: <p>I am building a select option dynamically. I am selecting from the select option, one value. (values for list come from php
  How can I pass that selected value to PHP?</p>
  
  <pre><code>&lt;select id ="s1" name="swimopt" class="so"&gt;
      &lt;?php echo $options; ?&gt;
  &lt;/select&gt;' 
  </code></pre>
  
  <p>THe $options are coming from a MySQL and populating the dropdown</p>
  
  <p>When I select a value, and try </p>
  
  <p><code>echo $_POST['swimopt'];</code> </p>
  
  <p>does not show selected value</p>
  
  <p>Please help</p>
  
  <pre><code> &lt;form id="swimdata"  method="POST" action="save.php"&gt;
  
       &lt;input type="radio" style="font-size: 16px;font-weight: bolder" name="gender" class ="gender" value="boys"&gt;BOYS
       &lt;input type="radio" style="font-size: 16px;font-weight: bolder" name="gender" class ="gender"  value="girls"&gt;GIRLS
  
       &lt;table id="meetTable" style="width:auto"&gt;
  
  
      &lt;tr&gt;
          &lt;th&gt;EVENT:&lt;/th&gt;
          &lt;th&gt;NAME:&lt;/th&gt;
          &lt;th&gt;LANE:&lt;/th&gt;
          &lt;th&gt;TIME:&lt;/th&gt;
          &lt;th&gt;PLACE:&lt;/th&gt;
          &lt;th&gt;SCORE 1:&lt;/th&gt;
          &lt;th&gt;SCORE 2:&lt;/th&gt;
          &lt;th&gt;PLACE:&lt;/th&gt;
          &lt;th&gt;TIME:&lt;/th&gt;
          &lt;th&gt;LANE:&lt;/th&gt;
          &lt;th&gt;NAME:&lt;/th&gt;
  
      &lt;/tr&gt;
  
  &lt;/table&gt;
  
       &lt;input type="submit" name="formSubmit" value="Submit" /&gt;
       &lt;input type="hidden" name="action1" value="addSwimmer" id="action1"&gt;
  
   &lt;/form&gt;
  </code></pre>
  
  <p>This is my PHP getting the $options from mySQL</p>
  
  <pre><code>if ($result-&gt;num_rows &gt; 0) {
      $options= '';
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
          $options .=  "&lt;tr&gt;&lt;td&gt;" . $row["swimmer_id"]. "&lt;/td&gt;&lt;td&gt;" . $row["first_name"]. " " . $row["last_name"]. " &lt;/td&gt;&lt;td&gt; "  . $row["school_name"]. "&lt;/td&gt;&lt;/tr&gt;";
      }
  
  } else {
      echo "0 results";
  }
  echo $options;
  $conn-&gt;close();
  </code></pre>
  
  <p>ScreenShots:</p>
  
  <p><a href="https://i.stack.imgur.com/88Iy3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/88Iy3.png" alt="Image of Select options in UI"></a></p>
  
  <p><a href="https://i.stack.imgur.com/iguBI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iguBI.png" alt="List inside dropdown"></a></p>
  
  <p>Options echoed into select box:</p>
  
  <pre><code>&lt;select id ="s1" name="swimopt" class="so"&gt;
      &lt;?php echo $options; ?&gt;
  &lt;/select&gt;' 
  </code></pre>
  
  <p>PHP file code</p>
  
  <pre><code>$sql = "select  first_name, last_name  from swimming where gender='m'";
  
  $results = mysqli_query($link,$sql);
  
  if ($results-&gt;num_rows &gt; 0) {
      $options = '';
      // output data of each row
      while($row = $results-&gt;fetch_assoc()) {
          $fname=$row["first_name"];
          $lname=$row["last_name"];
  
          $options .= "&lt;option value= &gt;" . $row["first_name"] . "  " . $row["last_name"]."&lt;/option&gt;";
  
  
      }
  } else {
      echo "0 results";
  }
  echo $options;
  $link-&gt;close();
  
  
  ?&gt;
  </code></pre>