I'm trying to populate my select dropdown menu from the names in my database MySQL, all I'm getting is a blank dropdown with nothing in it and not even expanding.
Database: ICADBS504A
CREATE TABLE IF NOT EXISTS `category` (
`cat_id` int(11) NOT NULL,
`cat_name` varchar(40) NOT NULL,
`cat_path` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
INSERT INTO `category` (`cat_id`, `cat_name`, `cat_path`) VALUES
(1, 'Computers', 'uploads/1/'),
(2, 'Phones', 'uploads/2/'),
(3, 'Toys', 'uploads/3/'),
(4, 'Pet Accessories', 'uploads/4/'),
(5, 'Camping', 'uploads/5/');
Form:
<select name="category">
<?php
// Make the connection:
$dbc = mysqli_connect ('localhost', 'root', 'password', 'ICADBS504A');
// If no connection could be made, trigger an error:
if ($dbc->connect_error)
{
die("Database selection failed: " . $dbc->connect_error);
}
# Set encoding to match PHP script encoding.
mysqli_set_charset($dbc, 'utf8');
$q = "SELECT cat_id, cat_name FROM category ".
"ORDER BY cat_name";
$r = mysqli_query($q);
while($row = mysqli_fetch_array($r))
{
echo "<option value=\"".$row['cat_id']."\">".$row['cat_name']."</option>\n ";
}
?>
</select>