Forum Moderators: coopster
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.
[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");
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