As dagon points out, you should use an if() statement to see if $_POST['query'] is set ([man]isset[/man]).
Also, note that you should never place user-supplied data directly into a SQL query as this will leave you vulnerable to SQL injection attacks. Instead, you should sanitize all user-supplied data with a function such as [man]mysql_real_escape_string/man.