How to insert Custom html form data into Database

I have created a custom html form in templates/pages directory.i have to add html form data into database. In which file i can write the code.Can any one help me?