First off I am new to PHP,
I am trying to display categories from a mysql db in a drop down menu.
for some reason it is not displaying the category options.
Need help with the code. Can anyone help me out.
"the db has two fields "id" & "category_name"
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="images"; // Database name
$tbl_name="categories"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "SELECT id,category_name FROM categories ORDER BY category_name";
echo '<select name="category_name">';
foreach ($conn->query($sql) as $row) {
echo '<option value="'.$row['id'].'">'.$row['category_name'].'</option>';
}
echo '</select>';
?>