Skip to main content
Participant
June 2, 2008
Question

insert multiple choices into mysql field

  • June 2, 2008
  • 4 replies
  • 3113 views
I have a form that inserts a record into mysql. it's working fine except when i changed the pull-down menu to a list allowing multiple selections, it only inserts the last item selected. I know it should insert the valuse as comma separated. Here's the php:
GetSQLValueString($_POST['not_reen_list'], "text"),
and the HTML:
<select name="not_reen_list" size="10" multiple="multiple" id="not_reen_list">
<option value="Nothing selected" selected="selected">Please select one</option><option value="Cost">Cost</option>
<option value="School could not meet our financial aid needs"> School could not meet our financial aid needs </option>
<option value="Prefer another school">Prefer another school </option>
</select>
Any help is appreciated.
This topic has been closed for replies.

4 replies

Participating Frequently
June 17, 2008
yes they do look terribly complicated
Inspiring
September 22, 2012

i have just used dacid powers code, it places all the content in one feild, is this correct?

Participating Frequently
September 24, 2012

>i have just used dacid powers code, it places

>all the content in one feild, is this correct?

Storing more than one value in a database column violates rules of database normalization. Generally, it should be avoided. What is the nature of the data you are storing?

Participating Frequently
June 9, 2008
omg XD so complecated codes XD, thanks anyway
cgrrayAuthor
Participant
June 2, 2008
Thank you David. I appreciate your help.
Inspiring
June 2, 2008
awsweb wrote:
> I have a form that inserts a record into mysql. it's working fine except when i
> changed the pull-down menu to a list allowing multiple selections, it only
> inserts the last item selected.

That's because you're not sending the form data as an array.

Change this:

<select name="not_reen_list"

to this:

<select name="not_reen_list[]"

At the top of the PHP script, convert the array to a comma-separated
string by adding this:

if (isset($_POST['not_reen_list'])) {
$_POST['not_reen_list'] = implode(',', $_POST['not_reen_list']);
}

I know it should insert the valuse as comma
> separated. Here's the php:
> GetSQLValueString($_POST['not_reen_list'], "text"),
> and the HTML:
> <select name="not_reen_list" size="10" multiple="multiple" id="not_reen_list">
> <option value="Nothing selected" selected="selected">Please select
> one</option><option value="Cost">Cost</option>
> <option value="School could not meet our financial aid needs"> School
> could not meet our financial aid needs </option>
> <option value="Prefer another school">Prefer another school </option>
> </select>
> Any help is appreciated.
>


--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
June 8, 2008
This helped me as well.

Now the question I have is there a way to then return that data back in to the multiple select box and have it selected?

Many thanks.