user2433662
user2433662

Reputation:

Populate Dropbox on Webpage with Database Query

I am trying to populate a dropbox on my webpage using information that is stored in a database. When I load the page, the dropbox is empty and none of the information following the dropbox is displayed.

PHP FOR DROPBOX:

        <?php 
            $sql_query = mysql_query("SELECT state_abbr, state_name FROM state_t ORDER BY state_name");
            echo '<select name="State">';
            while ($row = myssql_fetch_array($sql_query))
            {
                echo '<option value="'.$row['state_abbr'].'">'.$row['state_name'].'</option>';
            }
            echo "</select>";
        ?>

THE ENTIRE FORM ELEMENT HTML

<form
    action="http://webdev.spsu.edu/formtest.php"
    method="post">
    <div class="content">
    <table class="formTable">
        <tr>
            <td><label for="firstname">First Name:&nbsp;</label></td>
            <td><input type="text" name="First_Name" id="firstname" size="25" /></td>
            <td><label for="lastname">Last Name:&nbsp;</label></td>
            <td><input type="text" name="Last_Name" id="lastname" size="25" /></td>
        </tr>
        <tr>
            <td><label for="StreetAdd">Street Address:&nbsp;</label></td>
            <td><input type="text" name="Street_Address" id="StreetAdd" size="25" /></td>
            <td>Select State:&nbsp;</td>
            <td>
                <?php 
                    $sql_query = mysql_query("SELECT state_abbr, state_name FROM state_t ORDER BY state_name");
                    echo '<select name="State">';
                    while ($row = myssql_fetch_array($sql_query))
                    {
                        echo '<option value="'.$row['state_abbr'].'">'.$row['state_name'].'</option>';
                    }
                    echo "</select>";
                ?>
            </td>
            <td><label for="ZipCode">Zip Code:&nbsp;</label></td>
            <td><input type="text" name="Zip_Code" id="ZipCode" size="25" /></td>
        </tr>
        <tr>
            <td><label for="appleorderquantity">Apple Quantity (pounds):&nbsp;</label></td>
            <td><input type="text" name="Apple_Quantity" id="appleorderquantity" size="25" /></td>
            <td><label for="grapeorderquantity">Grape Quantity (pounds):&nbsp;</label></td>
            <td><input type="text" name="Grape_Quantity" id="grapeorderquantity" size="25" /></td>
            <td><label for="strbryorderquantity">Strawberry Quantity (pounds):&nbsp;</label></td>
            <td><input type="text" name="Strawberry_Quantity" id="strbryorderquantity" size="25" /></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td>Select Payment Method:<br /></td>
            <td>
                <label>MasterCard 
                    <input type="radio" name="Pref_Payment" id="pref_pay_Mcard" 
                        value="MasterCard" checked="checked" />
                </label>
                <br />
                <label>Visa 
                    <input type="radio" name="Pref_Payment" id="pref_pay_Visa" 
                        value="Visa" />
                </label>
                <br />
                <label>American Express
                    <input type="radio" name="Pref_Payment" id="pref_pay_AmEx" 
                        value="American Express" />
                </label>
                <br />
                <label>Discover
                    <input type="radio" name="Pref_Payment" id="pref_pay_Disc" 
                        value="Discover" />
                </label></td>
            <td></td>
            <td></td>
        </tr>
    </table>
    </div>
<div class="submitButton">
    <input type="submit" value="Submit" onClick="return validateOrder()" />
</div>
</form>

THIS IS WHAT IS DISPLAYING enter image description here THIS IS WHAT I WANT TO DISPLAY enter image description here

Upvotes: 0

Views: 171

Answers (1)

larsAnders
larsAnders

Reputation: 3813

You have a typo in this line:

while ($row = myssql_fetch_array($sql_query))

It should be:

 while ($row = mysql_fetch_array($sql_query))

It helps, while debugging, to see what errors are happening. You can add this line to an individual script to show all errors:

error_reporting(E_ALL);

Also, it's time to stop using the deprecated mysql functions. Switch to mysqli for MySQL only, or if you switch to PDO you can interface with MySQL and lots of other database types (MSSQL, Oracle, PostgreSQL, SQLite, etc...).

Upvotes: 2

Related Questions