<?php
// Database connection settings
require 'shikanisha.kts.php';

// Get the POST data
$name = $_POST['name'];
$quantity = $_POST['quantity'];
$unit = $_POST['unit'];
$cost = $_POST['cost'];
$initial_date = date('Y-m-d');

// Insert data into the database
$sql = "INSERT INTO ingredients (name, quantity, unit, cost_per_unit, initial_date) VALUES ('$name', $quantity, '$unit', $cost, '$initial_date')";

if ($conn->query($sql) === TRUE) {
    $response = array(
        "status" => "success",
        "message" => "New record created successfully"
    );
    echo json_encode($response);
} else {
    $response = array(
        "status" => "error",
        "message" => "Error: " . $sql . "<br>" . $conn->error
    );
    echo json_encode($response);
}

// Close the connection
$conn->close();
?>
