Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jan 27, 2011 Jan 27, 2011

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

TOPICS
Server side applications
780
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 27, 2011 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 27, 2011 Jan 27, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines