drafat
drafat

Reputation: 23

MySQL query issue : WHERE clause

I recently switched from windows (movamp) to linux (lamp), and i have an issue (syntax error) with a query and i can't figure out why. Here is the query and the error msg I get:

"SELECT * FROM products WHERE trash='false'"

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'false\'' at line 1SELECT * FROM products WHERE trash='false'

I always wrote my queries with that syntax, and i never had problems.

I used to run my code on windows (php 4.1.22 mysql 5.2.11) and used mysql_query() function, and the code worked just fine. Now I use(php 7.0.8 - mysql 5.7.16) and use mysqli_query() function to execute queries

Upvotes: 2

Views: 89

Answers (4)

drafat
drafat

Reputation: 23

I would like to thank you all for your answers and your comments. You helped me figure out what the problem was : the entire query string was beeing escaped instead of only the data tha needed to ne escaped.

I feel dumb 😁 . This was obvious.

Anyway. Thank you a lot for your contibution.

Upvotes: 0

Álvaro González
Álvaro González

Reputation: 146330

Your syntax error shows some bogus backslashes that are not present in the query, as if you are actually running this:

SELECT * FROM products WHERE trash=\'false\'

Not having even a full PHP statement to inspect we can only speculate, and my guess is that —since you are upgrading from a really ancient PHP version— you might be facing some issues with magic quotes. That "feature" no longer exists so nothing in the server can be injecting backslashes automatically so it must be your code the one that's intentionally doing it.

Said that, PHP/4 was superseded by PHP/5 in 2004 (that's like 12 years) and a lot has changed on the way to PHP/7: migration is going to be harder than just dropping the code in the new server.

Upvotes: 1

Rossitten
Rossitten

Reputation: 1166

"SELECT * FROM `products` WHERE `trash` ='false'"

try this (though your case should also work)

also try to remove the double quotes if you are trying to run SQL query in PHPMYadmin or likes.

Upvotes: 0

Jaithra Bopanna KK
Jaithra Bopanna KK

Reputation: 11

Try removing the single quotes , or try reversing the single and double quotes . IF nothing works use a variable with false value.

Upvotes: 0

Related Questions