Not executing the MYSQL query in the script

The question was asked: 49 years 9 months ago   views: 10

The problem is this: generated string from the selected options

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

then $query is passed to mysqli->query($query); and then nothing happens,no error messages. Output $query to the screen for visual verification,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 most interesting is that the query works!

What's the problem? If this request is to assign the $query,it runs successfully,but the settings does not want. Thank you

Asked: 01-01-1970 в 03:00:00
format the message, check what says echo $mysqli->error; and explain the purpose WHERE TRUE AND - 16-01-2013 в 11:44:01
What a strange question? After executing the query,nothing happens, although if you copy the resulting query string and execute directly,then it works. So I ask again, what do not understand my question - 16-01-2013 в 12:21:27

Answers   1


The query should be in single quotes to take

$query = 'SELECT * FROM catalog_test TRUE AND picture WHERE = $where';
Answered: 16-01-2013 в 12:42:26
Thanks, but not helped. Again, nothing happens, but the query runs.(i.e. the string is constructed correctly) - 16-01-2013 в 12:50:14
given that where the variable already contains a single quote, the answer is not entirely true. Quotes inside need escapeth. Either use double quotes. - 16-01-2013 в 12:57:22
@cerberus teach-line variable substitution in single quotes not carried out - 16-01-2013 в 14:41:15
KoVadim,it is possible more in detail about the quotes? Found out, if you only assign $where = ' AND picture = "+"' Query works. And when $where contains AND ( name LIKE('%Ariocarpus %') OR name LIKE('%Astrophytum %') OR name LIKE('%Aylostera %') OR FALSE) is not working - 16-01-2013 в 14:47:41
The problem is solved!! If anyone is interested, the bug was not in the query (as I thought), and in the table field on which the search was underway, the name of each line escaped the newline,so the request was empty. - 16-01-2013 в 16:26:06