Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

HTML 'list/menu' and PHP/mysql

list/menu and php/mysql

8:50 pm on Sep 22, 2004 (gmt 0)

New User

10+ Year Member

joined:Sept 22, 2004
votes: 0


Can anyone please tell me the correct syntax to use for assigning the selected option from a pick-list before inserting to a mysql database?

I am trying to give the visitor the option of some 20-30 categories from a pick-list and then I want to store the selected category in a field (called 'cat') in my mysql table.

Not having a lot of luck!


2:06 pm on Sept 23, 2004 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
votes: 0

what you call a "pick-list" is more commonly known as a "select box". Here is a simple example.


<form action="process.php" method="POST">
<select name="cat">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
<option value="5">five</option>


// do your database connection
$query="INSERT INTO mytable (cat) VALUES ('".$_POST['cat']."')";
print("your wish is my command");

3:33 pm on Sept 23, 2004 (gmt 0)

New User

10+ Year Member

joined:Sept 22, 2004
votes: 0

Hi httpwebwitch!

Thanks for the code.

Since posting I did get it to work using a rather strange -

echo "<option value=bus"; if ($r->category == 'bus') echo " SELECTED"; echo ">Business</option>";


Yours looks far simpler, less coding and neater.

...and point taken : pick-list==select box!