Display information in dropdown list from database query PHP/HTML

351

I'm having trouble with a bit of code I wrote, I can't seem to find any problems with it and its driving me crazy

    // create connection
$conn=odbc_connect('SkyeGaccess1','','');

if (!$conn)
  {exit("Connection Failed: " . $conn);}

  $sql = "SELECT Username FROM Customers";
$rs = mysql_query($sql);

echo "<select name='Username'>";
while ($row = mysql_fetch_array($rs)) {
    echo "<option value='" . $row['Username'] ."'>" . $row['Username'] ."</option>";
}
echo "</select>";
odbc_close($conn);
?>

I've looked around everywhere and this seems to be exactly how I'm supposed to write this piece of code. Its not a problem with the database connection as I can put the information into a table just fine, but I just can't get it to show up on the dropdown list.

537

Answer

Solution:

Replace with this code. This will help!

$conn=mysqli_connect('SkyeGaccess1','','');//altered
if (!$conn)
  {die("Connection Failed: " . $conn);}//altered

  $sql = "SELECT Username FROM Customers";
$rs = mysqli_query($sql);

echo "<select name='Username'>";
while ($row = mysqli_fetch_array($rs)) { //altered
    echo "<option value='" . $row['Username'] ."'>" . $row['Username'] ."</option>";
}
echo "</select>";
?>

Ping here on any issues!

People are also looking for solutions to the problem: php - CronJob not running CakePHP3

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.