What is wrong with this sql query?

what is wrong with this sql query. I can’t figure it out.

$query = "SELECT * FROM tagPairs WHERE (tag1Id IN ($tag1Id, $tag2Id)) AND (tag2Id IN ($tag1Id, $tag2Id))"; 

error code:

Query failed: you have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use next to it)) AND (tag2Id IN (,)) on line 3

early!

+4
source share
3 answers

$tag1Id and $tag2Id are empty or empty. The simplest solutions probably obviously lead them to numerical values:

  $ tag1Id = intval ($ tag1Id);
 $ tag2Id = intval ($ tag2Id);
 $ query = "SELECT *
     FROM tagPairs
     WHERE (tag1Id IN ($ tag1Id, $ tag2Id))
     AND (tag2Id IN ($ tag1Id, $ tag2Id)) ";
+4
source

$tag1Id and $tag2Id are empty.

This is why your error says (tag2Id IN (, )) .

+3
source

Your $tag1Id and $tag2Id are empty lines. Assign them a value and it should work fine.

Also, choosing * is a bad idea. Select the columns you want.

+1
source

Source: https://habr.com/ru/post/1301288/


All Articles