Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:39:53+00:00 2026-05-23T22:39:53+00:00

I have the following multi select box in a HTML form: <select multiple=multiple name=fruits>

  • 0

I have the following multi select box in a HTML form:

<select multiple="multiple" name="fruits">
    <option value="Apple">Apple</option> 
    <option value="Peach" selected="selected">Peach</option> 
    <option value="Banana">Banana</option> 
    <option value="Grapes" selected="selected">Grapes</option> 
</select>

How can I convert the selected values into a string of comma separated values for inserting into the database?

I am using PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:39:53+00:00Added an answer on May 23, 2026 at 10:39 pm

    Using PHP, I had to use name="fruits[]" (note the brackets) to get multiple values to post.

    From there, you get an array for $_POST['fruits'] (numerically indexed, values corresponding to what was selected), so implode(',', $_POST['fruits']) would give you the values as a comma separated string.

    However, if you are worried about true CSV format, you will need to escape the delimiters and enclose the values (there could be commas in the values, for instance). If you are confident that none of the values will break the output, and explode(',', $string) will get you back your array, implode() is fine.

    Also perhaps of interest:

    • http://php.net/manual/en/function.serialize.php
    • http://php.net/manual/en/function.unserialize.php

    Related:

    • Convert array into csv
    • Any function to take an array of strings and return a CSV line?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following multi-select box in a HTML form, where user can select
I have the following HTML code: <html> <head> <title>Cheeses</title> </head> <body> <select name=multi id=multi
I do have a multi select dropdown box. I want all the selected items
I have a multi-select drop down as following, where I have selected the options
I have a form with the following HTML below: <form id=course_edit_form name=course_form action=/courses/save method=post>
I have a listbox (multi-select) in my web form that is populated from a
I have the following problem using a has_many :through many-to-many relation in a multi-select
How do you setup a multi-developer XDebug PHP environment? I have the following setup:
I have models similar to the following: class Band(models.Model): name = models.CharField(unique=True) class Event(models.Model):
I have an ASP.NET webform that has a listbox ( lbxRegions ) with multi-select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.