<?php 

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ){

    require_once 'db_connect.php';
    $category_name = $_POST['category_name'];
    $shop_id = $_POST['shop_id'];
    $owner_id = $_POST['owner_id'];
 
    $sql = "SELECT * FROM product_category WHERE product_category_name='$category_name' AND shop_id='$shop_id' AND owner_id='$owner_id'";
    
    $result = mysqli_query($con, $sql);
    $num_rows = mysqli_num_rows($result);
    
    if ($num_rows > 0) {
        $response["value"] = "exists";
        echo json_encode($response);
    } else {
        $query = "INSERT INTO product_category (product_category_name, shop_id, owner_id) VALUES ('$category_name', '$shop_id', '$owner_id')";
        
        if (mysqli_query($con, $query)) {
            $response["value"] = "success";
            echo json_encode($response);
        } else {
            $response["value"] = "failure";
            echo json_encode($response);
        }
    }
    
    mysqli_close($con);
} else {
    $response["value"] = "failure";
    echo json_encode($response);
}
?>

