使用javascript继续或进入PHP循环

I am in a interesting problem. There is a foreach loop, this loop insert data into mysql table form a excel file for every row in excel file. Sometimes duplicate data comes out from excel which is natural. When this duplicate data attempt to insert, I want a popup to ask user that he is interested to insert duplicate data or not. If yes the rest of the code in PHP foreach loop will execute otherwise it will continue with next loop. Please help.

In PHP you need to process the excel file and halt processing when you see a duplicate and store the current position of the file perhaps in session. Your code should look at this flag to alert the user with popup. Once the user selects yes, you move the position in file and continue processing. This could be achieved with AJAX or without through multiple submissions.

Here is some pseudo code:

// is there a current saved pos?
$pos = getSavedPos();   
if ($pos) {
    moveToPos($pos);
}

// process file
while (!$endOfFile) {
    $pos        = getCurrentPosOfFile();
    $data       = getRowData();
    $duplicate = isDuplicateData($data);
    if ($duplicate) {
        savePos($pos);
        break;
    }
    else {
        insertDataIntoDb($data);
    }
}

// code elsewhere
if ($duplicate) {
    alert('This file contains duplicate information. Do you wish to continue?');
}