<?php
include "dbconfig.php";
$link = opencon();

// Check if data is received from the AJAX request
if (isset($_POST['checkedIds']) && is_array($_POST['checkedIds'])) {
    // Retrieve the checkedIds array
    $checkedIds = $_POST['checkedIds'];

    // Loop through the checkedIds array and update records
    foreach ($checkedIds as $id) {
        // Prepare and execute the SQL update query for each ID
        $manager = $_POST['selectedemployee'];
        $leader = $_POST['selectedemployee2'];
        $telecaller = $_POST['selectedemployee3'];
        
        $sql = "UPDATE new_lead SET Team_Manager='$manager', Team_Leader='$leader', Telecaller='$telecaller' WHERE id='$id'";
        
        if (mysqli_query($link, $sql)) {
            echo "Record with ID $id updated successfully<br>";
        } else {
            echo "Error updating record with ID $id: " . mysqli_error($link) . "<br>";
        }
    }
} else {
    echo "No data received or data format is incorrect.";
}

// Close the database connection
mysqli_close($link);
?>
