Home » Php » insert multiple option in the database – PHP

insert multiple option in the database – PHP

Posted by: admin February 22, 2020 Leave a comment

Q(Question):

how can i insert multiple option selected on a select box?
how can insert them in the database ?

A(Answer):

We Can Store Multiple Select Options on an array and save the values to the database using comma-separated.

<label for="services">Select Services :</label>
<select id="sel_services" name="services[]" multiple="multiple">
<option value="engine-oil-change">Engine Oil Change</option>
<option value="ac-service">AC Service</option>
<option value="wheel-alignment">Wheel Alignment</option>
<option value="normal-service">Normal Service</option>
<option value="body-washing">Body Washing</option>
</select>

processController.php

$service = implode(',', $_POST['services']);