I have an HTML form which is processed with PHP.
The input in the form is used as a condition in a SQL WHERE clause.
When there is no input the WHERE clause looks for an empty string and won't return anything. Instead I want to return ALL rows.
How can this be achieved? I thought about using LIKE instead but I want to match only exact input when there is indeed input.
To be clear:
I want to check if the variable that the input is stored in is empty. If so, I want to return all rows.
I wanted to know if it is possible to do such thing in SQL without having to change the statement around. Rather, by just changing the variable.
Note that there can be multiple fields of input.
EDIT:
Ignore the possibility of security risks. Is there a SQL command that can achieve this without changing the query itself, just the variables? For the record I am already checking if the variables are empty strings before the query. Also, where would the security risk be if I am checking if the variables are empty or not and I am doing proper validation otherwise?