You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.2 KiB
88 lines
3.2 KiB
6 months ago
|
<?php
|
||
|
require 'db_connection.php';
|
||
|
session_start();
|
||
|
|
||
|
// Check if admin is logged in
|
||
|
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||
|
header("Location: login.php");
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Check if the user ID is provided
|
||
|
if (isset($_GET['id'])) {
|
||
|
$user_id = intval($_GET['id']);
|
||
|
$user = $conn->query("SELECT * FROM users WHERE id = $user_id")->fetch_assoc();
|
||
|
|
||
|
if (!$user) {
|
||
|
echo "User not found.";
|
||
|
exit;
|
||
|
}
|
||
|
} else {
|
||
|
header("Location: admin_dashboard.php");
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Update user details on form submission
|
||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
|
$email = $_POST['email'];
|
||
|
$role = $_POST['role'];
|
||
|
$first_name = $_POST['first_name'];
|
||
|
$last_name = $_POST['last_name'];
|
||
|
$phone = $_POST['phone'];
|
||
|
|
||
|
$stmt = $conn->prepare("UPDATE users SET email = ?, role = ?, first_name = ?, last_name = ?, phone = ? WHERE id = ?");
|
||
|
$stmt->bind_param("sssssi", $email, $role, $first_name, $last_name, $phone, $user_id);
|
||
|
|
||
|
if ($stmt->execute()) {
|
||
|
header("Location: admin_dashboard.php");
|
||
|
exit;
|
||
|
} else {
|
||
|
echo "Error updating user.";
|
||
|
}
|
||
|
}
|
||
|
?>
|
||
|
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>Edit User</title>
|
||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<?php include 'includes/header.php'; ?>
|
||
|
|
||
|
<div class="container mt-5">
|
||
|
<h1>Edit User</h1>
|
||
|
<form method="POST">
|
||
|
<div class="mb-3">
|
||
|
<label for="email" class="form-label">Email</label>
|
||
|
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($user['email']) ?>" required>
|
||
|
</div>
|
||
|
<div class="mb-3">
|
||
|
<label for="role" class="form-label">Role</label>
|
||
|
<select class="form-select" id="role" name="role" required>
|
||
|
<option value="donor" <?= $user['role'] === 'donor' ? 'selected' : '' ?>>Donor</option>
|
||
|
<option value="recipient" <?= $user['role'] === 'recipient' ? 'selected' : '' ?>>Recipient</option>
|
||
|
<option value="admin" <?= $user['role'] === 'admin' ? 'selected' : '' ?>>Admin</option>
|
||
|
</select>
|
||
|
</div>
|
||
|
<div class="mb-3">
|
||
|
<label for="first_name" class="form-label">First Name</label>
|
||
|
<input type="text" class="form-control" id="first_name" name="first_name" value="<?= htmlspecialchars($user['first_name']) ?>">
|
||
|
</div>
|
||
|
<div class="mb-3">
|
||
|
<label for="last_name" class="form-label">Last Name</label>
|
||
|
<input type="text" class="form-control" id="last_name" name="last_name" value="<?= htmlspecialchars($user['last_name']) ?>">
|
||
|
</div>
|
||
|
<div class="mb-3">
|
||
|
<label for="phone" class="form-label">Phone</label>
|
||
|
<input type="text" class="form-control" id="phone" name="phone" value="<?= htmlspecialchars($user['phone']) ?>">
|
||
|
</div>
|
||
|
<button type="submit" class="btn btn-primary">Update User</button>
|
||
|
</form>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|