0

SQL statement is:

SELECT * 
FROM cigardata 
WHERE Brand LIKE '$brandS' 
  AND Style LIKE '$styleS' 
  AND Wrapper LIKE '$wrapperS' 
  AND UPC LIKE '$upcS';

User inputs Brand and Wrapper only and it will return nothing, normal since nothing in the other 2 fields. If I fill all 4 fields of course it works perfect. What can be used in the other 2 fields as a wild card to satisfy that all 4 fields are filled and return a result? I have tried %.%, %''%, %*%. Any suggestions......

5
  • 2
    just don't add AND field like "$field" for non defined ones? Commented Feb 19, 2019 at 16:23
  • For matching anything, you can use just a single '%'. But the first comment is a better solution to your specific problem. Commented Feb 19, 2019 at 16:30
  • 1
    the program should build the query dynamically based on the user input. Commented Feb 19, 2019 at 16:32
  • So if you have "user inputs", where are they? What kind of application is this? We need more information before we can help you. There are various ways to solve this, but we need more information. Commented Feb 19, 2019 at 16:41
  • It is a combination of HTML and PHP. User inputs are via a text box in the HTML part and then in the PHP part: $brandS=$_POST["brandS"]; Also there are precautions take to prevent SQL Injection. Commented Feb 19, 2019 at 18:29

1 Answer 1

0

isaace answer was the clue, the word "dynamically" led me to a solution that has been answered previously. Had to tweek it a bit with single quotes on the {$field1} to '{$field1}' and so on with the field 2 field 3 etc. Crating a Dynamic Search

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.