35370-vm/edit-dependent.php
Flatlogic Bot 275165284b 1.0
2025-10-31 00:13:36 +00:00

65 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
if (!isset($_GET['id'])) {
header('Location: index.php');
exit;
}
$dependent_id = (int)$_GET['id'];
$pdo = get_db_connection();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Handle form submission for updating the dependent
$full_name = $_POST['full_name'] ?? '';
$relationship = $_POST['relationship'] ?? '';
$date_of_birth = $_POST['date_of_birth'] ?? '';
$stmt = $pdo->prepare(
'UPDATE dependents SET full_name = ?, relationship = ?, date_of_birth = ? WHERE id = ?'
);
$stmt->execute([$full_name, $relationship, $date_of_birth, $dependent_id]);
header('Location: index.php?success_message=Dependent updated successfully');
exit;
}
// Fetch the dependent to edit
$stmt = $pdo->prepare('SELECT * FROM dependents WHERE id = ?');
$stmt->execute([$dependent_id]);
$dependent = $stmt->fetch();
if (!$dependent) {
header('Location: index.php');
exit;
}
include __DIR__ . '/layout/header.php';
?>
<h1>Edit Dependent</h1>
<form action="edit-dependent.php?id=<?php echo $dependent_id; ?>" method="post">
<div class="form-group">
<label for="full_name">Full Name</label>
<input type="text" id="full_name" name="full_name" value="<?php echo htmlspecialchars($dependent['full_name']); ?>" required>
</div>
<div class="form-group">
<label for="relationship">Relationship</label>
<input type="text" id="relationship" name="relationship" value="<?php echo htmlspecialchars($dependent['relationship']); ?>" required>
</div>
<div class="form-group">
<label for="date_of_birth">Date of Birth</label>
<input type="date" id="date_of_birth" name="date_of_birth" value="<?php echo htmlspecialchars($dependent['date_of_birth']); ?>" required>
</div>
<button type="submit" class="btn">Update Dependent</button>
</form>
<?php include __DIR__ . '/layout/footer.php'; ?>