0) { $stmt = $pdo->prepare("SELECT username FROM users WHERE id = ?"); $stmt->execute([$userId]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ($user) { $username = $user['username']; } } $stmt = $pdo->prepare( "INSERT INTO activity_log (user_id, username, action, details, timestamp) VALUES (?, ?, ?, ?, NOW())" ); $stmt->execute([$userId, $username, $action, $details]); } catch (PDOException $e) { error_log("Error logging activity: " . $e->getMessage()); } } ?>