Skip to main content
Known Participant
January 27, 2011
Question

Submitting an empty search returns all records (php / MySql)

  • January 27, 2011
  • 2 replies
  • 782 views

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?

Thanks

This topic has been closed for replies.

2 replies

January 27, 2011

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.

January 27, 2011

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.