Since your question is rathe generic, it's worth just browsing this board and looking at similar threads (the search function is good for that), or searching with Google. www.hotscripts.com is a large library of code snippets, who will have examples of what you want to do.
If you have any specific questions, I'll be glad to help. To compare form fields, you need to use the $POST array (which form fields get added to on a POST submission) or the $GET array (for query string variables).