How to update a field when a user views a page I am building a site for a client that is effectively a job board with a messaging system.  They want to know who the last person in their office was to view a specific application and to know who/when someone views specific pages/messages.  

I am hoping for something like 

set x = users.lastvisitor 
if currentuser != users.last vistor
insert currentuser &amp; date into users.lastvisitor 


Can anyone point me in a direction?  I am new to Craft so don't know how it handles things like this. I am using matrix blocks for the messages, is it possible to add an entry through a query instead of a form?
There's a plugin called Entry Count that updates a counter record every time a visitor loads a page. You might be able to adapt that plugin to check to see if the user is logged in, and if so, record their user ID to the database instead of incrementing the hit counter. The value is displayed on the Craft entry list dashboard, you would just want to adapt that to display the username instead of the ID.