Iterate dropdown checkbox selected value to insert records

I have an ADD page with one of the field is a Dropdown checkbox where you can select multiple value.For example:Field 1: ‘Test’
Field 2: ‘K001, K002, K003’ (This is dropdown checkbox where I selected 3 values)
Field 3: 'test value 3’How do I interate the 3 values in Field2 and insert 3 different records when I click Add where the value for Field 2 will be ‘K001’, ‘K002’ and ‘K003’ for each of the records. Can I do this in Row_Inserting to repeat the insert records 3 times?

Meaning to day, in my database will have the following record:Record 1
Field 1: ‘Test’
Field 2: ‘K001’
Field 3: 'test value 3’Record 2
Field 1: ‘Test’
Field 2: ‘K002’
Field 3: 'test value 3’Record 3
Field 1: ‘Test’
Field 2: ‘K003’
Field 3: ‘test value 3’

Yes. You may simply use “Row_Inserting” server event to do that.

Thanks. I got it working. In my original code, I mistakenly trying to insert into a Custom Field which is non-existent in my table.

However, using my code above, it also insert the original record with the Field2 containing all 3 values like the example below. How can I prevent this without having to write another query to delete Record 4?Record 1
Field 1: ‘Test’
Field 2: ‘K001’
Field 3: 'test value 3’Record 2
Field 1: ‘Test’
Field 2: ‘K002’
Field 3: 'test value 3’Record 3
Field 1: ‘Test’
Field 2: ‘K003’
Field 3: 'test value 3’Record 4
Field 1: ‘Test’
Field 2: ‘K001,K002,K003’
Field 3: ‘test value 3’

Solved… Thanks

// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {
    // Enter your code here
    // To cancel, set return value to FALSE

    $field2array = explode(',', $rsnew['field2']);

    if (count($field2array)>1){
      $last = array_pop($field2array); //remove last element in the array
  
      foreach ($field2array as $value){ // Loop through all the records
        ew_Execute("INSERT INTO table1 (field1, field2, field3) VALUES ('". $rsnew['field1'] . "', '". $rsnew['field2'] . "', '". $value . "') ");
      }

      //after inserting all records above (minus the last value in the array), reassign the previously assigned 
      //last element back to to field2 so row_inserting will automatically insert it
      $rsnew['field2'] = $last;
    }
    return TRUE;
}

I just cannot get this to work using the code supplied.I am using PHPMaker 2020 and seem to have problem with the SQL when inserting rows as the script does not fail when I comment out the line that starts ew_Execute.Any pointers would be appreciated.

Read Migrating to v2019 and update your code.