Dropdown form that shows data from 2 different tables I am very new to this and am using php and MySQLi to create a form which will create a record in a third table.  This works fine but I can't help but think that there is a way to do it with a single query rather than a query for each table as I have now.  The third table is called tblcars, and I will use this form to build records for that table by selecting data from these dropdowns.

    &lt;?php

    //Database Login
    require_once 'includes/connection.php';

    $sql = ("SELECT * FROM tblmake");

    $getclass = ("SELECT * FROM tblclass");

    $result = $conn-&gt;query($sql);
    $results = $conn-&gt;query($getclass);

    ?&gt;

    &lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Car Makes&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;

        &lt;h3&gt;Car Makes&lt;/h3&gt;      
            &lt;form action="" method="get"&gt;
            &lt;select name="makeID"&gt;
                &lt;option value=""&gt;Choose Make&lt;/option&gt;
                &lt;?php 
                    while($make = $result-&gt;fetch_assoc()) {
                        echo "&lt;option value={$make['makeID']}&gt;";
                        echo $make['carmake'];
                        echo "&lt;/option&gt;";
                    }
                ?&gt;
            &lt;/select&gt;
            &lt;select name="classID"&gt;
                &lt;option value=""&gt;Choose Class&lt;/option&gt;
                &lt;?php 
                    while($class = $results-&gt;fetch_assoc()) {
                        echo "&lt;option value={$class['classID']}&gt;";
                        echo $class['carclass'];
                        echo "&lt;/option&gt;";
                    }
                ?&gt;
            &lt;/select&gt;
            &lt;input type="submit" value="Insert"&gt;
        &lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
I don't see how you could do this in a single queries, because both queries have nothing to do with each other.

Your code does contain a bit of duplication, but otherwise it looks good to me.

You can simplify your code by introducing a function:

&lt;?php
    createTableSelectForm($conn, $table, $columnValue, $columnShow, $title) {
        $sql = ("SELECT * FROM " . $table);
        $results = $conn-&gt;query($sql);
        $form = '
                &lt;select name="makeID"&gt;
                    &lt;option value=""&gt;Choose ' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '&lt;/option&gt;';
        while($result = $results-&gt;fetch_assoc()) {
            $form .= '&lt;option value="' . htmlspecialchars($result[$columnValue], ENT_QUOTES, 'UTF-8') . '"&gt;';
            $form .=  htmlspecialchars($result[$columnShow], ENT_QUOTES, 'UTF-8');
            $form .= '&lt;/option&gt;';
        }
        $form .= '&lt;/select&gt;';
        return $form;
    }

    require_once 'includes/connection.php';
?&gt;
    &lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Car Makes&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;

        &lt;h3&gt;Car Makes&lt;/h3&gt;      
            &lt;form action="" method="get"&gt;
            &lt;?php echo createTableSelectForm($conn, "tblmake", "makeID", "carmake", "Make");
            echo createTableSelectForm($conn, "tblclass", "classID", "carclass", "Class"); ?&gt;
            &lt;input type="submit" value="Insert"&gt;
        &lt;/form&gt;

    &lt;/body&gt;
    &lt;/html&gt;


You really only need the first two arguments for the createTableSelectForm, but I added the other ones so that the method is more reusable.

I also added XSS protection, because with variable data, you can never be sure where it comes from (maybe, in the future you will allow visitors to add makes? Or now that the function is reusable, it will be reused somewhere else with user input? Who knows, and better safe than sorry; it also doesn't add that much overhead).

Misc


your naming is a bit confusing. The same thing should always have the same name, because it increases readability . But you have $sql and $getclass for basically the same thing. The same goes for $result vs $results (both hold multiple results). $sqlSelectMake/$sqlSelectClass and $resultMakes/$resultClasses would be better.