query returns all records in error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

query returns all records in error

Post by jarow »

I have a query that looks like this:

SELECT species, comname
FROM passerines
WHERE species LIKE '%varspecies%' AND comname LIKE '%varcomname%'


varspecies
value = 1
runtime value= $HTTP_GET_VARS['varspecies']

varcomname, same basically as as varspecies but with change of name.


In my search form, if I put a search value in one of the fields that has no approximate corresponding value in the database I get the message "No results found" which is exactly what I am supposed to get.

However, if I leave the search form blank, without adding values, and then press submit...all the records are listed on the results page.

I am not clear how to tell it if both (in this case) search text boxes are left empty "No results found" should appear just like mentioned above.

Any advice?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

1) You should take a look at the MySQL manual regarding searches using the '%' operator.

2) If both fields are left empty, why run the query in the first place? Either tell the user they left the fields empty or just simply return "No results found".

Cheers,
BDKR
Post Reply