I am trying to insert the values into the database and as you notice this is a multiple selection form field select menu. My problem is that when is inserted into the database, only one selection gets posted. Is there anything that I have to do on the server side to input all the values? or the client side? Any suggestions/tips/help would be greatly appreciated!
Name your form field with [] (eg. <select size="3" name="selection[]" multiple="multiple">). That will pass the values to PHP as an array. Now, you can loop through the array, and insert into the DB.
(Just guessing, I have yet to work with a multiple select in PHP.)
[Edit: I see Pyro beat me to the punch. ]
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
it is not passing the values to the variable because I think it is not recognizing the array. I am sure that I am inserting to the right function from the form right?
That will just insert a serialized version of the array into the database. While technically it would work (you could unserialize it later), I would recommend looping through the array and running the SQL that way. If you describe what you want (how the data is to be stored in the DB), I can get you an example to look at, in the hopes that you'll be able to learn from it.
I can see the selections made but How do I get rid of the extra information. Perhaps something like:
Art, Art History, etc. in the database would be proper.
I was going crazy finding out the solution for this and I was not looking outside the box! Nicely done! and it implements commas and stuff. Good work! Thanks.
Jaelan - for future reference, since you aren't doing anything with the array key, you don't even need to assign it. You can run your foreach loop like this:
Hah,
Neat. Actually, I copied the foreach from above and just put my code in it. It shows I don't know much about 'foreach', but because it simplified my code, I'm changing it in my actual application. Thanks for the suggestion..
Jaelan
"I killed the world once! You can too, if you try hard!"
--Lews Therin,
Robert Jordan's "The Wheel of Time"
Bookmarks