You may want to take a look a Request Tracker. I believe that it already does what you are after. Here is an excerpt from the the Features section of the website.
Features
RT is a robust ticketing system designed for the small-to-medium sized
enterprise. It can be used for customer support, bugtracking, trouble ticketing, or any other purpose for which a group of folks need to keep track of a list of tasks. It features a number of technologies designed to make it easy
to keep track of a large number of tasks, issues and projects:
- Web, email and commandline interfaces. The web interface is designed to work well with all popular browsers, including console-based browsers.
- Web interface for each end-user to quickly check on the status of his open tickets.
- Data is stored in an SQL database which you can audit and report on using standard tools.
- Granular access control system which allows users to do their work but also protects the system.
- Flexible 'keywords' system which allows a local site to keep track of ticket metadata in the most sensible way.
- Extensible linking system which allows you to tie tickets to each other and to external databases. (RT supports dependencies, parent-child relationships and generic relationships)
- Clean object oriented design makes it a breeze to build new tools which work with RT's tickets, queues, users and links.
- Open 'Scrips' system allows sites to drop in custom business logic which persists transparently across system upgrades.
- Doesn't cost anything to set up and use. (Available under the terms of the GNU GPL)
Being someone who has tried to build a support desk, I would strongly recommend using free stuff that already exists. If you still want to do it yourself, then have a look at what other people have done.
Kristofer A. Hoch