1) Google is your friend, a google search for:
how to create a chat box
yielded a number of good results.
2) to be successful creating this you will need a good understanding of relational databases and how to use a linking table to create a many to many relationship between a users table and a classes table.
this goes beyond what I can teach you in this forum
here is a decent video tutorial to get started with many to many relationships: