<?php
require __DIR__ . "/db.php";

$division = $_POST['division'] ?? '';
$name     = $_POST['name'] ?? '';

$division = trim($division);
$name     = trim($name);

if ($division === '' || $name === '') {
    echo "0";
    exit;
}

// Cek duplikasi
$stmt = $conn->prepare("SELECT id FROM division_names WHERE division=? AND name=? LIMIT 1");
$stmt->bind_param("ss", $division, $name);
$stmt->execute();
$stmt->store_result();

if ($stmt->num_rows > 0) {
    echo "1";
    exit;
}
$stmt->close();

// Insert baru
$stmt = $conn->prepare("INSERT INTO division_names (division, name) VALUES (?, ?)");
$stmt->bind_param("ss", $division, $name);

echo $stmt->execute() ? "1" : "0";
$stmt->close();