The problem is as follows: a string is generated from the selected parameters

$query = SELECT * FROM catalog_test WHERE TRUE ".$where; 

then $query is passed to mysqli->query($query); and nothing else happens, no error messages. I deduced $query on the screen for visual check, it turns out for example:

 SELECT * FROM catalog_test WHERE TRUE AND picture = '+' AND ( name LIKE('%Ariocarpus %') OR name LIKE('%Astrophytum %') OR name LIKE('%Aylostera %') OR FALSE) 

And the most interesting is that this query works!

What is the problem? If we assign $ query to this query, then it succeeds, but does not want with parameters. thank

  • format the message, check what echo $mysqli->error; writing echo $mysqli->error; and explain the purpose of the WHERE TRUE AND - Gedweb
  • What exactly is not clear question? After the request, nothing happens, although if you copy the resulting query string and execute it directly, it works. Therefore, I ask again what my question is incomprehensible - Igrik

1 answer 1

The request must be in single quotes

 $query = 'SELECT * FROM catalog_test WHERE TRUE AND picture = $where'; 
  • Thanks, but did not help. Again, nothing happens, but the request is directly executed. ( Ie, the string is formed correctly) - Igrik
  • Considering that the where variable already contains a single quote, the answer is not entirely correct. Quotes inside need to escape. Either use double quotes. - KoVadim
  • @cerberus teach strings, variable substitution in single quotes is not performed - Gedweb
  • KoVadim, is it possible in more detail about quotes? I figured out if I assign only $ where = 'AND picture = "+"' The request works. And when $ where also contains AND (name LIKE ('% Ariocarpus%') OR name LIKE ('% Astrophytum%') OR name LIKE ('% Aylostera%') OR FALSE does not work - Igrik
  • Problem solved !! If anyone is interested, the error was not in the request (as I thought), but in the field of the table that the search was going on, the line-feed character was hidden in the name of each line, so the request was empty. - Games