80 lines
2.5 KiB
PHP
80 lines
2.5 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['member_id']) || !filter_var($_GET['member_id'], FILTER_VALIDATE_INT)) {
|
|
header('Location: index.php?error_message=Invalid+member');
|
|
exit;
|
|
}
|
|
|
|
$member_id = (int)$_GET['member_id'];
|
|
|
|
// Fetch member details
|
|
$pdo = get_db_connection();
|
|
$stmt = $pdo->prepare('SELECT full_name FROM members WHERE id = ?');
|
|
$stmt->execute([$member_id]);
|
|
$member = $stmt->fetch();
|
|
|
|
if (!$member) {
|
|
header('Location: index.php?error_message=Member+not+found');
|
|
exit;
|
|
}
|
|
|
|
$error_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (empty($_POST['full_name']) || empty($_POST['relationship']) || empty($_POST['date_of_birth'])) {
|
|
$error_message = 'All fields are required.';
|
|
} else {
|
|
$stmt = $pdo->prepare(
|
|
'INSERT INTO dependents (member_id, full_name, relationship, date_of_birth) VALUES (?, ?, ?, ?)'
|
|
);
|
|
|
|
try {
|
|
$stmt->execute([
|
|
$member_id,
|
|
$_POST['full_name'],
|
|
$_POST['relationship'],
|
|
$_POST['date_of_birth'],
|
|
]);
|
|
header('Location: index.php?success_message=Dependent+added+successfully');
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
$error_message = "Error adding dependent: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
include __DIR__ . '/layout/header.php';
|
|
?>
|
|
|
|
<h1>Add Dependent for <?php echo htmlspecialchars($member['full_name']); ?></h1>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form action="add-dependent.php?member_id=<?php echo $member_id; ?>" method="post">
|
|
<div class="form-group">
|
|
<label for="full_name">Full Name*</label>
|
|
<input type="text" id="full_name" name="full_name" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="relationship">Relationship*</label>
|
|
<input type="text" id="relationship" name="relationship" required placeholder="e.g., Spouse, Child, Parent">
|
|
</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" required>
|
|
</div>
|
|
|
|
<button type="submit" class="btn">Add Dependent</button>
|
|
<a href="index.php" class="btn" style="background-color: #6c757d; border-color: #6c757d;">Cancel</a>
|
|
</form>
|
|
|
|
<?php include __DIR__ . '/layout/footer.php'; ?>
|