<?php
require_once "../config/db.php";

$id = (int) $_POST['id'];

$customer_id = $_POST['customer_id'];
$service_name = trim($_POST['service_name']);
$type = $_POST['type'];
$amount = $_POST['amount'];
$cost = $_POST['cost'];
$start_date = $_POST['start_date'];
$renewal_date = $_POST['renewal_date'];

if(empty($service_name)){
    die("Service name required");
}

$stmt = $conn->prepare("
UPDATE services SET 
customer_id=?,
service_name=?,
type=?,
amount=?,
cost=?,
start_date=?,
renewal_date=?
WHERE id=?
");

$stmt->bind_param(
    "issddssi",
    $customer_id,
    $service_name,
    $type,
    $amount,
    $cost,
    $start_date,
    $renewal_date,
    $id
);

$stmt->execute();

header("Location: ../pages/services.php");
exit;
