I’m trying to insert information into my databased
I know how to do this using a form and text fields…but i was wondering if someone could help me with how to make a drop down list that is populated with all the information in a field.
the table i’m grabbing from looks like this
Table: category
Field1: sub_cat_id
Field2: sub_cat_name
I want the drop down to be filled with the category names
I’ve searched for several tutorials and tried a lot of them but i either end up with an empty drop down or the code appearing on the screen.
PHP Code:
[LEFT] [COLOR=#000000] [COLOR=#0000BB][/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]html[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]head[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]title[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Add Vendor[/COLOR][COLOR=#007700]</[/COLOR][COLOR=#0000BB]title[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]head[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]body bgcolor[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“white”[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]form method[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“POST” [/COLOR][COLOR=#0000BB]action[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“vendor_add.php”[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]table[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]col span[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“1” [/COLOR][COLOR=#0000BB]align[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“right”[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Company Name[/COLOR][COLOR=#007700]:</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“text” [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“name” [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]100[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Company Reference [/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]name with no spaces[/COLOR][COLOR=#007700]):</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“text” [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“vendor_ref” [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]100[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Address [/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]ex[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]1234 Main St[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]Brampton[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]Ontario[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]Canada[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]L1V 3K4[/COLOR][COLOR=#007700]):</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“text” [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“addr” [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]100[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Phone [/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]inc[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]area code[/COLOR][COLOR=#007700]):</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“text” [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“phone” [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]100[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Email[/COLOR][COLOR=#007700]:</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“text” [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“email” [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]100[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Website [/COLOR][COLOR=#007700](if [/COLOR][COLOR=#0000BB]available[/COLOR][COLOR=#007700]):</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“text” [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“website” [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]100[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Category[/COLOR][COLOR=#007700]:</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
— [/COLOR][COLOR=#0000BB]THIS IS WHERE I WANT THE DROP DOWN [/COLOR][COLOR=#007700]—
</[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]font color[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“blue”[/COLOR][COLOR=#007700]>[/COLOR][COLOR=#0000BB]Promo[/COLOR][COLOR=#007700]:</[/COLOR][COLOR=#0000BB]font[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“text” [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“promo” [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]100[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]><[/COLOR][COLOR=#0000BB]input type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“submit” [/COLOR][COLOR=#0000BB]value[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]“Submit”[/COLOR][COLOR=#007700]></[/COLOR][COLOR=#0000BB]td[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]tr[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]table[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]form[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]body[/COLOR][COLOR=#007700]>
</[/COLOR][COLOR=#0000BB]html[/COLOR][COLOR=#007700]>
[/COLOR][COLOR=#0000BB][/COLOR] [/COLOR] [/LEFT]
If i enter code like this one below…into the spot designated above…it just prints part of it onto the screen. I don’t know if this is written wrong…of i’m putting it in the wrong spot.
<?
$query="SELECT sub_cat_id, sub_cat_name FROM category";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query);
echo "<select name=category value=''></option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[sub_cat_id]>$nt[sub_cat_name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
Thanks for any help!