begin_transaction(); try { $stmt = $mysqli->prepare(" UPDATE $tableTurnerinnenAbt SET turnerin_index = ? WHERE turnerin_id = ? "); foreach (['new', 'old'] as $bucket) { if (empty($input[$bucket])) continue; foreach ($input[$bucket] as $row) { $stmt->bind_param("ii", $row['order_index'], $row['id']); $stmt->execute(); } } $mysqli->commit(); http_response_code(200); } catch (Throwable $e) { $mysqli->rollback(); http_response_code(500); }