Occasionally words get confusing.  Here the same word is used for two things.  You can get data from an SQL database using a SELECT query and then use it to create an HTML select element (a drop down).  Before you read this page make sure you understand how to create a select element in HTML and what part option elements play.

You should be able to adapt what you learned about how to create a list in PHP to creating a select by using PHP to get data from an SQL server.  For a list you had:

  1. the opening list tag
  2. a while loop which creates the list items
  3. the closing list tag

For a drop down (select) you use the same basic principles.  Look at this example but don't paste the code.  Try to understand what is happening:

<body>

    <form method="post" action="https://www.yourwebskills.com/files/examples/process.php">
        
        <select id="cd" name="cd">
        
            <?php
            
            $cdquery="SELECT cdTitle FROM firsttable";
            $cdresult=mysqli_query($dbconnection, $cdquery) or die ("Query to get data from firsttable failed: ".mysqli_error($dbconnection));
            
            while ($cdrow=mysqli_fetch_array($cdresult)) {
            $cdTitle=$cdrow["cdTitle"];
                echo "<option>
                    $cdTitle
                </option>";
            
            }
                
            ?>
    
        </select>
        
        <input type="submit">
    </form>
    
</body>

Save sqllist.php (from beginnerssite) as sqldropdown.php.  Adapt that page by doing this:The completed drop down

  1. change the database name to intsql if necessary
  2. change the second echo line so that it creates a <select> opening tag instead of a <ul>
  3. inside the loop change the echo line so that it creates option elements instead of li elements
  4. test it and the drop down will work although it has no purpose yet
  5. steal ideas and code from the above example to turn your page into a functioning form:
    1. using that action will allow you to test that your choice is sent properly
    2. as you are using echo for the select you will need to escape the quotes
    3. make sure you include all tags as pairsThe posted data

The most likely errors are not escaping quotes.

You could add a blank entry in the drop down by adding it before the loop.  If your database held the appropriate data you could also have one item selected by default (you just need to add a selected field to the table and enter 1 in it for the default name).