<?php

require_once '../config/database.php';

$db = getDB();

$deviceId =
$_POST['device_id'] ?? '';

$productId =
intval($_POST['product_id'] ?? 0);

if(empty($deviceId) || $productId == 0){

    echo json_encode([

        "success" => false
    ]);

    exit;
}

$check = $db->query("

SELECT id
FROM favorites

WHERE device_id = '$deviceId'

AND product_id = $productId
");

if($check->num_rows == 0){

    $db->query("

    INSERT INTO favorites
    (device_id,product_id)

    VALUES
    ('$deviceId',$productId)
    ");
}

echo json_encode([

    "success" => true
]);