<?php
include("./include/config.php");

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Check if the selectedRows parameter is present in the POST request
    if (isset($_POST['selectedRows'])) {
        // Get the selected rows from the POST data
        $selectedRows = json_decode($_POST['selectedRows']);

        // Convert the selected rows into a comma-separated string for the SQL query
        $selectedRowsString = implode(',', $selectedRows);

        // Prepare the SQL query to delete the selected rows
        $sql = "DELETE FROM `sms` WHERE id IN ($selectedRowsString)";

        // Execute the SQL query
        if (mysqli_query($conn, $sql)) {
            // Deletion successful
            echo "Selected SMS rows deleted successfully";
        } else {
            // Error occurred during deletion
            echo "Error deleting SMS rows: " . mysqli_error($conn);
        }
    } else {
        // No selected rows found
        echo "No SMS rows selected for deletion";
    }
} else {
    // Invalid request method
    echo "Invalid request";
}

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