You need to initialise your db first.
Look at:
php-manual[
^]
When you do it as described put your mysql_query()-call before closing the connection.
btw: put your db-code and the redirect in your 'if (isset($_GET['q']) && $_GET['q'] != "")'-clause.