The table deportes has 2 columns with 4 rows:
<?php
$sql = 'SELECT * FROM deportes';
$resul = mysqli_query($conexion, $sql);
$deportes = array();    
while ($fila = mysqli_fetch_array($resul))
{
     $deportes[] = $fila;
}       
?>
The form with the select multiple options:
<select name="fan[]" multiple="multiple"> 
    <?php
        foreach ($deportes as $aficion)
        {
            echo "<option value='".$aficion['idD']."'";
            echo " >{$aficion['nombreDep']}  </option>\n";
        }
    ?>            
</select>
Get the values from the form
<?php
if (isset($_POST['fan']))
    {
    $sport = $_POST['fan'];
    }
?>
Now this
<?php $sport = mysqli_real_escape_string($conexion, $sport); ?>
This way insert the values in another table
$idPersona = mysqli_insert_id($conexion);           
$sql = "INSERT INTO mec(id,idD) VALUES ('$idPersona','$sport') ";
And the result is i get the value "0" in the field idD from table mec
 
     
     
    