Skip navigation
Currently Being Moderated

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

Jan 27, 2011 3:04 AM

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

 
Replies
  • Currently Being Moderated
    Jan 27, 2011 10:09 AM   in reply to Wookie

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 27, 2011 3:55 PM   in reply to Wookie

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points