prepare("UPDATE users SET role_id = ?, division_id = ?, department_id = ? WHERE id = ?"); $stmt->execute([$role_id, $division_id, $department_id, $user_id]); header('Location: user_management.php?success=user_updated'); exit; } catch (PDOException $e) { header('Location: edit_user.php?id=' . $user_id . '&error=db_error'); exit; } } try { // Fetch user data along with their division, department, and role IDs $stmt = $pdo->prepare("SELECT u.id, u.username, u.email, u.role_id, r.department_id, d.division_id FROM users u LEFT JOIN roles r ON u.role_id = r.id LEFT JOIN departments d ON r.department_id = d.id WHERE u.id = ?"); $stmt->execute([$user_id]); $user = $stmt->fetch(); if (!$user) { header('Location: user_management.php?error=user_not_found'); exit; } // Fetch all divisions $divisions = $pdo->query("SELECT id, name FROM divisions ORDER BY name")->fetchAll(); } catch (PDOException $e) { die('Database error: ' . $e->getMessage()); } ?> Edit User

Edit User:

An error occurred. Please try again.
Cancel