php - Search query with validation

Solution:
Your SQL is invalid because you have 2 WHERE clauses.
Change it to:
$sqlCommand = "SELECT * FROM albums WHERE userid='$id' AND (bor_mjesto LIKE %$searchquery%' OR bor_kucni_broj LIKE '%$searchquery%' OR bor_postanski_broj LIKE '%$searchquery%' OR bor_ulica LIKE '%$searchquery%' OR bor_opcina LIKE '%$searchquery%')";
(note the use of parentheses to surround the multiple "OR" statements)
Answer
Solution:
You need to drop the secondWHERE
(and add some parentheses), like this:
$sqlCommand = "
SELECT *
FROM
albums
WHERE
userid='$id'
AND
(
bor_mjesto LIKE '%$searchquery%' OR
bor_kucni_broj LIKE '%$searchquery%' OR
bor_postanski_broj LIKE '%$searchquery%' OR
bor_ulica LIKE '%$searchquery%' OR
bor_opcina LIKE '%$searchquery%'
)
";
You only have to useWHERE
once per query. Also, you don't need to add the single quotes around $id here, as it's an integer value.
Also, I'm not sure where your variables are coming from, but you'll probably want to escape them usingmysql_real_escape_string
before putting them into this query. Finally,SELECT *
is almost always a mistake: only select the rows you really need. That'll save you a bit of time :)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your system folder path does not appear to be set correctly. please open the following file and correct this: index.php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.