I have a php search page where if I enter a search term the correct results are displayed as required. However if I leave the search box empty and press submit, the results page displays all the records from the MySql database.
How do I prevent this from happening? How could I display some sort of error message when the user tries to submit an empty search?
It's easier to provide a solution when you provide the code. Otherwise you'll just be given a basic suggestion of creating a conditional region where if something, then something, else something else.
Before executing the SQL search, check that the search string is non-null (and not just spaces). Just check the input string using an IF statement in PHP.
If the string is blank, issue an error instead of the search results.