Anton Lunyov
Anton Lunyov

Reputation: 5

PHP Insertion - UID is larger for first entry

I am inserting two rows from a .csv into a table through PHP.

I am also keeping track of any errors, and if one occurs I don't commit the transactions. Upon insertion into the table, I retrieve the IDs of the resulting rows (which were all commited in one transaction) and the FIRST row of the csv corresponds to the SECOND ID. I also tried adding a mysqli_commit in various places, still the same issue

    $queryInsert = "INSERT INTO ".$table." VALUES(NULL,?,?,?,1,?)";
    if (!($stt= mysqli_prepare($con,$queryInsert))){
        die('Failed');
    }

    //some arbitrary data checking
    if ($cols[8] == 'No' || $cols[8] == 'N' || $cols[8] == '0'){
        $ref = 0;
    }else{
        $ref = 1;
    }

    mysqli_stmt_bind_param($stt,"ssii",$cols[6],$cols[7],$runUID,$ref);
    $in = mysqli_stmt_execute($stt);
    mysqli_stmt_close($stt);
    $uid = mysqli_insert_id($con);
    mysqli_commit($con);

    echo $uid;

If the previous row entry was 284, the output is 287 and 286 (it tried to insert 285 last time, failed, but the ID invalidity is somehow retained. So it attempts to insert 286 and 287, but tries to insert 287 before 286 and fails again). The second row (with the lower ID) is inserted perfectly fine, whereas the higher one is not. What is going on?

Upvotes: 0

Views: 14

Answers (1)

Anton Lunyov
Anton Lunyov

Reputation: 5

The issue was that a trigger was countering the entry. Fixed

Upvotes: 0

Related Questions