Doesnt look too bad for a first attempt.
Some improvements. try to seperate logic from presentation that is PHP seperate from HTML makes debugging easier.
Secondly your not validating any data going into the database. You should addslashes, if you require an integer as the data going into the database cast it using
(int)$var etc. Im sure someone is going to say dont use casts but they havent done anything wrong by me yet.
You could also use wish you can use strip_tags or htmlspecialchars/htmlentities .