i'm glad i confused you.... not really.
heres my previous example split into 2 files.
form.php
<?php
// other code
echo "<form method=\"Post\" action=\"formProcess.php\">";
echo "<select multiple name=\"key[]\" size=\"4\">";
echo "<option value=\"1\">Item 1</option>";
echo "<option value=\"2\">Item 2</option>";
echo "<option value=\"3\">Item 3</option>";
echo "</select>";
echo "<INPUT TYPE=\"submit\" name=\"action\" value=\"Submit\">";
echo "</form>";
?>
formProcess.php
<?php
if($_POST['action'] == "Submit"){
// then when you process your form do this
$key = implode(",", $key); // Or $item = implode(",", $_POST['item']);
echo "Value of key[]: $key";
// rest of code
// added your mysql query.
mysql_query("INSERT into table_name (field1, field2) values (NULL,$key)");
}
?>
i'm really not sure how you came up with
$key=implode(",",_$key); ??
see, this is the trick about this whole thing is this.
in <select multiple name="key[]">
key is what you want to pass from the form to the db. but you want to have multiple selections, so key has to be an array, that's why we use key[]
now when you pass the data from form.php to formProcess.php key is holding a value "array". But that isn't useful because you want the values 1,2,3,etc.... that's why in formProcess.php we do:
$key = implode(",",$_POST['key']);
this makes the value of key into something you can put into the db, like 1,2,3,etc....
Now here's some reading material:
What is PHP_SELF and $_POST[]? its a Predefined variable:
http://www.php.net/manual/en/language.variables.predefined.php
how to use implode?
http://www.php.net/manual/en/function.implode.php
How does this 'trick' work? A complete article and code snippet.
http://www.phpbuilder.com/columns/tim19991124.php3
this should hopefully clear some things up.
🙂