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>
<meta charset="utf-8">
<title>Add a new Gas Purchase Location</title>

<h1>Add a new Gas Purchase Location:</h1>

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

<form action="droptest1.php" method="post">
<table border=2>
    <TD><input type="date" name="DATE"></TD>
        <select name="LOCATION">
        while($rows = $resultset->fetch_assoc())
            $loc = $rows['LOCATIONS'];
            echo "<option value='$loc'>$loc</option>";
    <td><input type="submit"></td>

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

//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.