<?php
include('con.php'); // Connects using $ahk_conn

$message = "";

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $service = trim($_POST['service']);
    $rate = trim($_POST['rate']);

    if (empty($service) || !is_numeric($rate)) {
        $message = "Please enter valid service and numeric rate.";
    } else {
        $service_safe = mysqli_real_escape_string($ahk_conn, $service);
        $rate_safe = floatval($rate);

        $insert = mysqli_query($ahk_conn, "INSERT INTO price (service, rate) VALUES ('$service_safe', '$rate_safe')");

        if ($insert) {
            $message = "✅ Service added successfully!";
        } else {
            $message = "❌ Error: " . mysqli_error($ahk_conn);
        }
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Add Service Rate</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5" style="max-width: 500px;">
    <h4 class="mb-4 text-primary">Add Service Rate</h4>

    <?php if ($message): ?>
        <div class="alert alert-info"><?php echo $message; ?></div>
    <?php endif; ?>

    <form method="POST" action="">
        <div class="mb-3">
            <label for="service" class="form-label">Service Name</label>
            <input type="text" class="form-control" id="service" name="service" required>
        </div>
        <div class="mb-3">
            <label for="rate" class="form-label">Rate (₹)</label>
            <input type="number" step="0.01" class="form-control" id="rate" name="rate" required>
        </div>
        <button type="submit" class="btn btn-success w-100">Add Service</button>
    </form>
</div>
</body>
</html>
