How to implement a WordPress comments function?

Use comment_form() not a self made code. See the answers to question 15179 for a working example of a comments.php.