When posting PHP code, please use the board's [PHP][/PHP] bbcode tags (not just the generic CODE tags) - they make the code much, much easier to read (as well as aiding the diagnosis of syntax errors). You should edit your post now and add these bbcode tags to help others in reading/analyzing your code.
It appears as though you're vulnerable to SQL injection attacks. User-supplied data should never be placed directly into a SQL query! Instead, sanitize it with a function such as [man]mysql_real_escape_string/man.
As to your problem, I don't see where $db_name is ever defined (we can only assume what 'connect.php' does). At any rate, have you tried debugging the SQL query with the error message provided by the SQL server? If the query fails, I find it helpful to output both the query itself (so that you can visually inspect it) as well as the error message returned by MySQL (via [man]mysql_error/man).