well it would help if you could post your code, but I'm pretty sure I understand the problem. A switch statement to see whether the form button has been pressed will do it.
The form above can be a separate file and included in the default case or can be echoed in the default case.
<form action=<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Search <input type="text" name="search" />
<input type="submit" value="Search" name="button" />
} //end switch