<?php
require 'shikanisha.kts.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);

    $name = $data['name'];
    $quantity = $data['quantity'];

    // Insert the new tot into the database
    $query = "INSERT INTO tots (name, quantity) VALUES (?, ?)";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("si", $name, $quantity);
    $stmt->execute();
    
    // Handle success or error
    if ($stmt->affected_rows > 0) {
        echo json_encode(["message" => "Tot added successfully."]);
    } else {
        echo json_encode(["message" => "Failed to add tot."]);
    }
}
?>
