I have a MySQL table named Users
with columns Name
and NameID
.
Like...
Name | NameID
Brad | bd
Tom | ts
I'm trying to pull the all the Name
values and have them populate a dropdown list using mysqli. I'm running into problems and hoping someone here can help.
I'm new to mysqli, so struggling a bit here. Here's the code..
connect.php...
<?php
$dbname = 'mydabase';
$dbuser = 'myuser';
$dbpass = 'mypass';
?>
In index.php...
<?php
include ("connect.php");
$db = new mysqli('localhost', $dbuser, $dbpass, $dbnam);
if (!$db) {
exit('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
?>
<div class="label">Select Name:</div>
<select name="names">
<option value = "">---Select---</option>
<?php
$queryusers = "SELECT `Name` FROM `Users` ";
$db = mysqli_query($queryusers);
while ( $d=mysqli_fetch_assoc($db)) {
echo "<option value='{".$d['Name']."}'></option>";
}
?>
</select>