You're getting errors because you're attempting to read post variables that haven't been set, they only get set on form submission. Wrap your php code at the bottom in an
if ($_SERVER['REQUEST_METHOD'] === 'POST') { ... }
Also, your code is ripe for SQL injection. At the very least use mysql_real_escape_string
on the post vars before using them in SQL queries. mysql_real_escape_string
is not good enough for a production site, but should score you extra points in class.