2

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

4
  • use mysqli_escape_string because assigning them Commented Dec 7, 2016 at 7:38
  • have you tried without the single quotes? It seems like you trying to escape the single quotes and this is causing the issue Commented Dec 7, 2016 at 7:40
  • 1
    stackoverflow.com/questions/9596652/… Commented Dec 7, 2016 at 7:41
  • use false if the value is supposed to be string or use just false if the value is supposed to be boolean Commented Dec 7, 2016 at 7:44

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0
"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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.