<?php
require_once __DIR__ . '/../config/config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id'])) {
    $link_id = (int)$_POST['id'];
    
    $conn = db_connect();
    $sql = "UPDATE links SET click_count = click_count + 1 WHERE id = $link_id";
    $conn->query($sql);
    $conn->close();
    
    echo json_encode(['success' => true]);
} else {
    http_response_code(400);
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
}
