OpenGL first person camera orientation issues

I have a "camera" in my opengl program that I recently finished. However, I've noticed that whenever I rotate and then move again, the x, y, and z angles change. For example, when I press the "w" key, I move forward along the "z" axis. If I then rotate the camera 90 degrees, when I push the "W" key, I will actually be moving right, seemingly along the "x" axis. It makes sense why this happens, I'm just wondering why its happening. Here's the rotation function:

You are moving it along the axes, not along the view direction. Increment the position by the view direction vector. You can get it using the x and y angles, or you can extract it from the view matrix.The 3rd row is the negated view direction. So you can do: