multiple list values to one field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kristie380
Forum Commoner
Posts: 36
Joined: Sun Oct 09, 2005 10:51 pm

multiple list values to one field

Post 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!
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Post 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
kristie380
Forum Commoner
Posts: 36
Joined: Sun Oct 09, 2005 10:51 pm

Post 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\"
)";
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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.
Post Reply