You wisely check right off the bat whether or not you DO have a form submission.
Except that he is doing it wrong. Depending on a button to be submitted in order for the script to work will completely fail in certain cases.
OP, you need to check the Request Method
if ($_SERVER['REQUEST_METHOD'] == 'POST')
Do not create variables for nothing.
Never ever put variables in your query. You need to use prepared statements. I recommend you use PDO
Completely remove the form action