What are common pitfalls when inserting multiple values from a select dropdown into a database using PHP?

Common pitfalls when inserting multiple values from a select dropdown into a database using PHP include not properly handling the selected values as an array, not sanitizing the input data to prevent SQL injection, and not looping through the array of selected values to insert each one individually into the database.

// Assuming the form submits selected values as an array named 'selected_values'
if(isset($_POST['selected_values']) && is_array($_POST['selected_values'])) {
    $selected_values = $_POST['selected_values'];
    
    // Sanitize the input data
    $clean_values = array_map('mysqli_real_escape_string', $selected_values);
    
    // Loop through the array and insert each value into the database
    foreach($clean_values as $value) {
        $query = "INSERT INTO table_name (column_name) VALUES ('$value')";
        // Execute the query here
    }
}