Okay, you don't have to code a new forum yourself. There are many free open source forum software on the web. You can easily customize them for your own use using themes that are free or being sold on the forum themes section. You can also code your own once you master the code.
If you don't want to use those softwares and insist on coding your own, you can still use the software to give you an idea of how to do it. Just study the code which is in PHp format e.g PHPBB
etc and you'll get ideas on how you should design your forum program.