0

I´m trying to select all rows that contain $sql_eingabe in any column ('Vorname' and 'Name').

This first attempt works fine with just one column:

$sql = "SELECT * FROM Mitglied WHERE (Vorname) IN ($sql_eingabe)";

But when adding another column the query breaks

$sql = "SELECT * FROM Mitglied WHERE (Vorname, Name) IN (($sql_eingabe),($sql_eingabe))";

and I get this warning:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in...
Dharman
  • 30,962
  • 25
  • 85
  • 135
le_fisch
  • 31
  • 4
  • Why tagged with `php html` ? – B001ᛦ Dec 01 '17 at 15:23
  • 4
    Maybe I'm going crazy, but I don't see any difference between the first two code snipits you posted.... – ArcherBird Dec 01 '17 at 15:23
  • 1
    Your sql syntax is __invalid__ – u_mulder Dec 01 '17 at 15:26
  • @u_mulder is correct, the `IN` statement doesn't work like this for multiple columns. You will need to use some kind of `EXISTS` statement, depending on the logic you want, you might just use two `IN` statements with an `OR` – ArcherBird Dec 01 '17 at 15:28
  • Seems you are missing one closing ')' – Rool Paap Dec 01 '17 at 16:02
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Mar 01 '20 at 18:52

1 Answers1

1

Use correct syntax:

SELECT * 
FROM Mitglied 
WHERE 
    Vorname IN ('value1', 'value2')
OR
    Name IN ('value1', 'value2')
u_mulder
  • 54,101
  • 5
  • 48
  • 64