title: Issue with storing values of Multiselect in database
body: <p>Alright I have a hell of a problem right now .</p>
  
  <p>I have a bootstrap multiselect like below which allows me to add or remove groups for an user.</p>
  
  <p><a href="https://i.stack.imgur.com/M1jam.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M1jam.png" alt="enter image description here"></a></p>
  
  <p>Well it works but there is a bug which remove me 1 additional group each time I click on <code>"Submit"</code></p>
  
  <p>Example : If the user was in 3 groups( <code>blabla, bleble and blibli</code>) and I press <code>Submit</code> without even touching the groups, it will remove the user from 1 group and he will have only 2 left (<code>blabla and bleble</code>).</p>
  
  <p>Here is the <code>PHP</code> code i used for treatement :</p>
  
  <pre><code>$groupes = $_GET['groupes'];
  $idc = $_GET['idc'];
  if ($groupes != "null") {
      $g = explode(',', $groupes);
      for ($i = 0; $i &lt; count($g); $i++) {
  
          $sqlDel = "DELETE FROM appartenir  WHERE idc = $idc";
  
          $reqDel = mysqli_query($mysqli, $sqlDel) or die('Erreur SQL !&lt;br/&gt;' . $sqlDel . '&lt;br/&gt;' . mysqli_error($mysqli));
      }
  
      for ($i = 0; $i &lt; count($g); $i++) {
          $sql1 = "INSERT INTO appartenir(idc,idg) VALUES('$idc', '$g[$i]')";
          $req1 = mysqli_query($mysqli, $sql1) or die('Erreur SQL !&lt;br/&gt;' . $sql1 . '&lt;br/&gt;' . mysqli_error($mysqli));
      }
  
  }
  </code></pre>
  
  <p>And the <code>HTML</code>code of the select if it helps :</p>
  
  <pre><code> &lt;select id="filtreMultiselectModif" name="groupes[]" multiple="multiple"&gt;
  
                &lt;?php
  
              while ($data3 = mysqli_fetch_array($req3)) { // Remplissage du SELECT
                  $idg = $data3['idg'];
                  $intitule = $data3['intitule'];
                  ?&gt;
                  &lt;option value="&lt;?php echo $idg ?&gt;" selected&gt;&lt;?php echo $intitule ?&gt;&lt;/option&gt;
              &lt;?php } ?&gt;
              &lt;?php
  
  
              while ($data2 = mysqli_fetch_array($req2)) { // Remplissage du SELECT
                  $idg = $data2['idg'];
                  $intitule = $data2['intitule'];
                  ?&gt;
                  &lt;option value="&lt;?php echo $idg ?&gt;"&gt;&lt;?php echo $intitule ?&gt;&lt;/option&gt;
              &lt;?php } ?&gt;
  
          &lt;/select&gt;
  </code></pre>
  
  <p>I don't think putting the jquery code will be useful</p>
  
  <p>Any help will be appreciated !</p>