<?php
header('Content-Type: application/json');
$data = json_decode(file_get_contents('php://input'), true);

if (!$data || !isset($data['name']) || !isset($data['phone']) || !isset($data['type'])) {
    echo json_encode(['success' => false]);
    exit;
}

$host = "localhost";
$user = "blenco1_billing_system";
$password = "Hafshan@2552";
$dbname = "blenco1_billing_system";

$conn = new mysqli($host, $user, $password, $dbname);
if ($conn->connect_error) {
    echo json_encode(['success' => false]);
    exit;
}

$name = $conn->real_escape_string($data['name']);
$phone = $conn->real_escape_string($data['phone']);
$type = $conn->real_escape_string($data['type']);

$sql = "INSERT INTO customers (name, phone, type) VALUES ('$name', '$phone', '$type')";
if ($conn->query($sql)) {
    echo json_encode(['success' => true]);
} else {
    echo json_encode(['success' => false]);
}
?>