Welcome to WebmasterWorld Guest from 54.80.188.87

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
posts:2
votes: 0


Hi,

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!

Cheers.

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
posts:4061
votes: 0


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

[form.php]

<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>
</select>

[process.php]

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

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

New User

10+ Year Member

joined:Sept 22, 2004
posts:2
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>";

statement.

Yours looks far simpler, less coding and neater.

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

Muffinman

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members