# Inserting checkbox values as comma separated data into MySQL field

**URL:** <https://forum.kirupa.com/t/inserting-checkbox-values-as-comma-separated-data-into-mysql-field/326047>\
**Category:** programming\
**Created:** [November 19, 2011, 11:49pm UTC](https://forum.kirupa.com/t/inserting-checkbox-values-as-comma-separated-data-into-mysql-field/326047 "2011-11-19T23:49:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [November 19, 2011, 11:49pm UTC](https://forum.kirupa.com/t/inserting-checkbox-values-as-comma-separated-data-into-mysql-field/326047/1 "2011-11-19T23:49:19Z")

</div>

For some reason when I try to insert data from a form’s checkbox fields into a MySQL database, all that shows up in the database field is the word ‘Array’.

Below is the HTML form code I’m using:

```auto

  <div class="optionalField">
    <fieldset>
      <legend>Colors:</legend>
      <label for="availability_checkbox_0" class="labelCheckbox">
        <input type="checkbox" name="colors[]" id="colors[]" class="inputCheckbox" value="Rose madder" />
        Rose madder</label>
      <label for="availability_checkbox_1" class="labelCheckbox">
        <input type="checkbox" name="colors[]" id="colors[]" class="inputCheckbox" value="Cerulean blue" />
        Cerulean blue</label>
      <label for="availability_checkbox_2" class="labelCheckbox">
        <input type="checkbox" name="colors[]" id="colors[]" class="inputCheckbox" value="Sap green" />
        Sap green</label>
      <label for="availability_checkbox_3" class="labelCheckbox">
        <input type="checkbox" name="colors[]" id="colors[]" class="inputCheckbox" value="Pompeii Red" />
        Pompeii Red</label>
      <label for="availability_checkbox_4" class="labelCheckbox">
        <input type="checkbox" name="colors[]" id="colors[]" class="inputCheckbox" value="Pyrrol Crimson" />
        Pyrrol Crimson</label>
    </fieldset>
  </div>

```

And here is the PHP code that retrieves the array values (or is supposed to):

```auto

$colors = implode(',', $_POST['colors']);
// SQL injection and Headers are dealt with later...

```
