105 lines
3.9 KiB
PHP
105 lines
3.9 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;
|
|
}
|
|
|
|
$member_id = (int)$_GET['id'];
|
|
$pdo = get_db_connection();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Handle form submission for updating the member
|
|
$full_name = $_POST['full_name'] ?? '';
|
|
$street = $_POST['street'] ?? '';
|
|
$number = $_POST['number'] ?? '';
|
|
$neighborhood = $_POST['neighborhood'] ?? '';
|
|
$city = $_POST['city'] ?? '';
|
|
$state = $_POST['state'] ?? '';
|
|
$zip_code = $_POST['zip_code'] ?? '';
|
|
$phone = $_POST['phone'] ?? '';
|
|
$email = $_POST['email'] ?? '';
|
|
$job_title = $_POST['job_title'] ?? '';
|
|
$department = $_POST['department'] ?? '';
|
|
|
|
$stmt = $pdo->prepare(
|
|
'UPDATE members SET full_name = ?, street = ?, number = ?, neighborhood = ?, city = ?, state = ?, zip_code = ?, phone = ?, email = ?, job_title = ?, department = ? WHERE id = ?'
|
|
);
|
|
$stmt->execute([$full_name, $street, $number, $neighborhood, $city, $state, $zip_code, $phone, $email, $job_title, $department, $member_id]);
|
|
|
|
header('Location: index.php?success_message=Member updated successfully');
|
|
exit;
|
|
}
|
|
|
|
// Fetch the member to edit
|
|
$stmt = $pdo->prepare('SELECT * FROM members WHERE id = ?');
|
|
$stmt->execute([$member_id]);
|
|
$member = $stmt->fetch();
|
|
|
|
if (!$member) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
include __DIR__ . '/layout/header.php';
|
|
?>
|
|
|
|
<h1>Edit Member</h1>
|
|
|
|
<form action="edit-member.php?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" value="<?php echo htmlspecialchars($member['full_name']); ?>" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" name="email" value="<?php echo htmlspecialchars($member['email']); ?>" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="phone">Phone</label>
|
|
<input type="text" id="phone" name="phone" value="<?php echo htmlspecialchars($member['phone']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="street">Street</label>
|
|
<input type="text" id="street" name="street" value="<?php echo htmlspecialchars($member['street']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="number">Number</label>
|
|
<input type="text" id="number" name="number" value="<?php echo htmlspecialchars($member['number']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="neighborhood">Neighborhood</label>
|
|
<input type="text" id="neighborhood" name="neighborhood" value="<?php echo htmlspecialchars($member['neighborhood']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="city">City</label>
|
|
<input type="text" id="city" name="city" value="<?php echo htmlspecialchars($member['city']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="state">State</label>
|
|
<input type="text" id="state" name="state" value="<?php echo htmlspecialchars($member['state']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="zip_code">ZIP Code</label>
|
|
<input type="text" id="zip_code" name="zip_code" value="<?php echo htmlspecialchars($member['zip_code']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="job_title">Job Title</label>
|
|
<input type="text" id="job_title" name="job_title" value="<?php echo htmlspecialchars($member['job_title']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="department">Department</label>
|
|
<input type="text" id="department" name="department" value="<?php echo htmlspecialchars($member['department']); ?>">
|
|
</div>
|
|
|
|
<button type="submit" class="btn">Update Member</button>
|
|
</form>
|
|
|
|
<?php include __DIR__ . '/layout/footer.php'; ?>
|