<?php include '../db.php';

$id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM hostings WHERE id=?");
$stmt->execute([$id]);
$h = $stmt->fetch();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $stmt = $conn->prepare("UPDATE hostings SET plan=?, provider=?, start_date=?, expiry_date=?, price=? WHERE id=?");
    $stmt->execute([
        $_POST['plan'],
        $_POST['provider'],
        $_POST['start_date'],
        $_POST['expiry_date'],
        $_POST['price'],
        $id
    ]);
    header("Location: index.php");
}
?>

<h2>Edit Hosting</h2>
<form method="post">
    <input name="plan" value="<?= $h['plan'] ?>" required><br>
    <input name="provider" value="<?= $h['provider'] ?>" required><br>
    <input type="date" name="start_date" value="<?= $h['start_date'] ?>" required><br>
    <input type="date" name="expiry_date" value="<?= $h['expiry_date'] ?>" required><br>
    <input name="price" value="<?= $h['price'] ?>"><br>
    <button type="submit">Update</button>
</form>
