<?php

require_once "config.php";

header('Content-Type: application/json');

$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'GET') {
    $ckode = $_GET['ckode'] ?? '';
    $cusename = $_GET['cusername'] ?? '';
    
    // Prepare the DELETE statement
    $query = $conn->prepare("DELETE FROM tblike WHERE ckode = ? AND cusername = ?");
    $query->bind_param("ss", $ckode, $cusename);
    
    // Execute the query
    if ($query->execute()) {
        // Check if any rows were affected
        if ($query->affected_rows > 0) {
            echo json_encode(['message' => 'Record deleted successfully']);
        } else {
            echo json_encode(['message' => 'No matching record found']);
        }
    } else {
        echo json_encode(['error' => 'Failed to execute query']);
    }

    // Close the statement
    $query->close();
} else {
    echo json_encode(['error' => 'Method not allowed']);
}

mysqli_close($conn);
?>
