It looks like you are trying to use a single php page for doing everything you want. This is definitely possible, but if you are just beginning with PHP, I would suggest you split you functionality between two pages.
As you probably already know, good design documentation is necessary for ANY programs you write. If nothing else, it will help keep you focused whne you are coding. (I'm sure you did this right?) 🙂.
The first thing you need to decide is what will this program do.
It will present the user with an interface so they can select a category from the category table in your database.
It will take the user's selection and add it, along with some other info, into another database table.
These are the 2 pages and you can call them whatever you like.
categoryform.php
categoryformsubmit.php
It looks like you need a little help with your mysql database functions but I am not going to get into that. Your best bet is to dig through some online tutorials. I believe there are a few here.
Also look into using functions for doing a lot of this work for you. It will keep the main program logic seperate from the gory details of how it is done.
Good Luck.