Creating a search form and displaying results

Welcome to WordPress development!

There’s a few things to answer about your question, the first is regarding the hanging on a blank page. Usually that means there is an error of some sort; one of the most helpful things you’ll find during development is turning on WordPress’ DEBUG mode, which will instruct PHP to print out errors when anything goes wrong. This will help you immensly in tracking down the issue.

To switch on debug mode, open wp-config.php in the root of your WordPress install, look for WP_DEBUG, and set it to true. Make sure you set this back to false before your site goes live, because it’s insecure to have errors going out to anyone but yourself.

Once you’ve done that, trying to use the search form again should give you a somewhat meaningful error and that’ll help us track down where the issue is.

Now a couple of other things:

Unless PHP’s register_globals setting is turned on (which it shouldn’t be, because it’s a security risk – and has actually been removed in more recent versions of PHP anyway), your code actually is not going to work because the variables you’re calling haven’t been set yet. To use the form data, you’ll need to access the $_POST superglobal. Basically, each time you try to access a form field, do it like $_POST["searching"] instead of $searching. If you replace each of your field references with this, you might find that that solves the problem (unless there is something else I’m not noticing).

One other important thing to note is that your application is at risk of SQL injection. The user could enter anything in that search field… and if crafted carefully, it could do untold damage to your database. You’ll want to read up on http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks and most likely use the $wpdb->prepare() function to protect your query.

I know that’s probably a lot to take in; hopefully it guides you well, just let me know if you have any questions or if you get a different error after turning on DEBUG mode, and we can work through that!