prepare('UPDATE users SET username = ?, role = ?, password = ? WHERE id = ?'); $stmt->execute([$username, $role, $hashed_password, $user_id]); } else { $stmt = $pdo->prepare('UPDATE users SET username = ?, role = ? WHERE id = ?'); $stmt->execute([$username, $role, $user_id]); } header('Location: users.php?updated=true'); exit; } catch (PDOException $e) { $error_message = "Error updating user: " . $e->getMessage(); } } // Fetch user data try { $stmt = $pdo->prepare('SELECT username, role FROM users WHERE id = ?'); $stmt->execute([$user_id]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if (!$user) { header('Location: users.php'); exit; } } catch (PDOException $e) { die("Error fetching user data: " . $e->getMessage()); } $page_title = "Edit User"; include 'partials/header.php'; ?>
Edit User Details