0

So here is my conundrum: I am trying to create a form that will have a drop down list that is populated with information from a mysql data base. The code for the form file is:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Add a new Gas Purchase Location</title>
</head>

<body>
<center>
<h1>Add a new Gas Purchase Location:</h1>
<br><br>

<?php
include 'dbconnection.php';
$resultset = $conn->query("SELECT locations FROM locations");
?>

<form action="droptest1.php" method="post">
<table border=2>
<TR>
    <TH>DATE:</TH>
    <TD><input type="date" name="DATE"></TD>
</TR>
<TR>
    <TH>Location:</TH>
    <TD>
        <select name="LOCATION">
        <?php
        while($rows = $resultset->fetch_assoc())
        {
            $loc = $rows['LOCATIONS'];
            echo "<option value='$loc'>$loc</option>";
        }
        ?>
        </select>
    </td>
</TR>
<TR>
    <th></th>
    <td><input type="submit"></td>
</TR>
</form>
</center>
</body>
</html>

Here is the text of the dbconnection.php (I have blanked out the login information part of it:

<?php
//databade login information
$dbhost = "localhost";
$dbuser = "rev****";
$dbpass = "*******";
$dbname = "rev****";

// Create connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

// Check connection
if ($conn->connect_error)
{
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully" ;
?>

When I load the form, it looks correct but the drop down list isnt pulling the information from the table I need loaded. A screen shot of what it looks like when loaded is attached:

enter image description here

What am I doing wrong?

Here is a screen shot of the database structure from phpmyadmin:

enter image description here

New contributor
Jacob Stallings is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    This: $loc = $rows['LOCATIONS']; , might need to be: $loc = $rows['locations']; – Luuk Feb 12 at 15:04
  • BTW: database structures should NEVER be posted as a picture.....CREATE TABLE locations (id int(11) auto_increment primary key, locations text); is so much simpler. 😉 – Luuk Feb 12 at 15:05

Browse other questions tagged or ask your own question.