PHP

Retrieve the value of the selected option

HTML & PHP

<div class="demo-main-container">
 <div class="demo-form-container"> 

   <form action="" method="post"> 
   
    <div class="select-block">
	
        <select name="list_of_activities" class="form-select">

         <option value="" disabled selected> </option>

          <option value="swimming" <?php echo ($_POST['list_of_activities']=='swimming'?'selected':'')?>>Swimming</option>

          <option value="football" <?php echo ($_POST['list_of_activities']=='football'?'selected':'')?>>Football </option>

          <option value="yoga" <?php echo ($_POST['list_of_activities']=='yoga'?'selected':'')?>>Yoga</option>

          <option value="golf" <?php echo ($_POST['list_of_activities']=='golf'?'selected':'')?>>Golf</option>

          <option value="tennis" <?php echo ($_POST['list_of_activities']=='tennis'?'selected':'')?>>Tennis</option>

        </select>
		
    </div>
	
   <div class="container" style="margin-top: 20px;">
  <div class="row justify-content-between">
  
<div class="col-md-8">

<?php
  if(isset($_POST['submit'])){
  
  if(!empty($_POST['list_of_activities'])) {
  $activity_selected = $_POST['list_of_activities'];
  echo 'You have selected: <strong>' . $activity_selected . '</strong>';
} 

else {
  echo 'Please select an activity';
}

}
?>

</div>
<div class="col-md-4" style="text-align: right">
<input type="submit" name="submit" value="Submit" class="btn btn-secondary button-submit">
</div>
</div>
</div> 

   </form> 

 </div>
</div>