105 lines
3.5 KiB
PHP
105 lines
3.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';
|
|
|
|
$success_message = '';
|
|
$error_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Basic validation
|
|
if (empty($_POST['full_name']) || empty($_POST['email'])) {
|
|
$error_message = 'Full Name and Email are required.';
|
|
} else {
|
|
$pdo = get_db_connection();
|
|
$stmt = $pdo->prepare(
|
|
'INSERT INTO members (full_name, street, number, neighborhood, city, state, zip_code, phone, email, job_title, department) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
|
);
|
|
|
|
try {
|
|
$stmt->execute([
|
|
$_POST['full_name'] ?? null,
|
|
$_POST['street'] ?? null,
|
|
$_POST['number'] ?? null,
|
|
$_POST['neighborhood'] ?? null,
|
|
$_POST['city'] ?? null,
|
|
$_POST['state'] ?? null,
|
|
$_POST['zip_code'] ?? null,
|
|
$_POST['phone'] ?? null,
|
|
$_POST['email'] ?? null,
|
|
$_POST['job_title'] ?? null,
|
|
$_POST['department'] ?? null,
|
|
]);
|
|
header('Location: index.php?success_message=Member+added+successfully');
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
// In a real app, you might want to log this error
|
|
$error_message = "Error adding member: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
include __DIR__ . '/layout/header.php';
|
|
?>
|
|
|
|
<h1>Add New Member</h1>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form action="add-member.php" 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="email">Email*</label>
|
|
<input type="email" id="email" name="email" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="phone">Phone</label>
|
|
<input type="text" id="phone" name="phone">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="street">Street</label>
|
|
<input type="text" id="street" name="street">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="number">Number</label>
|
|
<input type="text" id="number" name="number">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="neighborhood">Neighborhood</label>
|
|
<input type="text" id="neighborhood" name="neighborhood">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="city">City</label>
|
|
<input type="text" id="city" name="city">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="state">State</label>
|
|
<input type="text" id="state" name="state">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="zip_code">ZIP Code</label>
|
|
<input type="text" id="zip_code" name="zip_code">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="job_title">Job Title</label>
|
|
<input type="text" id="job_title" name="job_title">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="department">Department</label>
|
|
<input type="text" id="department" name="department">
|
|
</div>
|
|
|
|
<button type="submit" class="btn">Add Member</button>
|
|
<a href="index.php" class="btn" style="background-color: #6c757d; border-color: #6c757d;">Cancel</a>
|
|
</form>
|
|
|
|
<?php include __DIR__ . '/layout/footer.php'; ?>
|