I’m not overly familiar with search results pages and how you edit them, but a quick fix for the problem you have is to check for an empty string in the first bit of code and say “Please enter a search term” or something if there isn’t one entered. You’d achieve that with something like:
<?php
if (empty($s)) {
_e('Please enter a search term');
} else {
$allsearch = new WP_Query("s=$s&showposts=-1");
$key = esc_html($s, 1);
$count = $allsearch->post_count;
_e(''); _e('“'); _e('<span class="searchTerm">');
echo $key;
_e('</span>'); _e('”'); _e(' - ');
echo $count . ' '; _e('found');
wp_reset_query();
}
?>
Extra stuff not relevant to your question: For the second bit of code it may be worth looking at the docs here https://developer.wordpress.org/reference/functions/query_posts/ and switching to using get_posts
, but as I said I’m not sure if using query_posts might be ok in this case for search pages. Certainly the docs say it shouldn’t be used in your own themes.