Page 1 of 1

multiple list values to one field

Posted: Fri Apr 27, 2007 3:46 pm
by kristie380
Is there a way to save multiple list selections from a form field into 1 field in MySQL? Right now it's only saving the first entry from my list. Thanks!

Posted: Fri Apr 27, 2007 4:04 pm
by timclaason
Do:

Code: Select all

<SELECT MULTIPLE NAME='choice[]'>
...
</SELECT>
Then on the post page:

Code: Select all

foreach($choice as $value) {
...
}
I think that will work

Posted: Fri Apr 27, 2007 4:21 pm
by kristie380
could you expand on the post page part? here is my code...


HTML:

Code: Select all

<select name='activities[]' size="10" multiple="multiple" id="activities">
....
</select>

PHP:

Code: Select all

$date = date("Y-m-d G:i:s");
$sql = "INSERT INTO `signup2` VALUES (
\"\", 
\"$_POST[firstname]\", 
\"$_POST[lastname]\", 
\"$_POST[maidenname]\", 
\"$_POST[gradyear]\", 
\"$_POST[email]\", 
\"$_POST[city]\", 
\"$_POST[state]\", 
\"$_POST[country]\", 
\"$_POST[url]\", 
\"$_POST[email_private]\", 
\"$_POST[aol]\",
\"$_POST[myspace]\",
\"$_POST[activities]\",
\"$_POST[update]\",
\"$_POST[username]\", 
\"$_POST[password]\",  
\"$date\",
\"$date\"
)";

Posted: Fri Apr 27, 2007 5:29 pm
by califdon
I fear that you're missing some fundamental concepts about databases and PHP. I know it's hard to get started and everyone always wants to have somebody "just tell me how to do this," but that's often not possible. Unless I don't understand your question, you should never try to do what you described, it violates the rules of relational database normalization.