[SOLVED] How to store multiple selected values from <select> tag in a single field

Issue

I have a select tag with multiple="multiple". And a user can select more than one value.

<label for="aoi">Area of Interest:</label>
<select id="sel_aoi" name="aoi" multiple="multiple">
    <option value="hr-executive">HR Executives</option>
    <option value="sr-manager">Sr. Manager</option>
    <option value="service-advisor">Service Advisor</option>
    <option value="production">Production Engineer</option>
    <option value="mechanical">Mechanical Engineer</option>
</select>

How I can store these more than one selected values in single field of MySQL database?

Solution

Store it to an array and save the values to database using comma seprated.

<label for="aoi">Area of Interest:</label>
          <select id="sel_aoi" name="aoi[]" multiple="multiple">
            <option value="hr-executive">HR Executives</option>
            <option value="sr-manager">Sr. Manager</option>
            <option value="service-advisor">Service Advisor</option>
            <option value="production">Production Engineer</option>
            <option value="mechanical">Mechanical Engineer</option>
          </select>

process.php

$aoi = implode(',', $_POST['aoi']);

Answered By – Avin Varghese

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.