Home php MySQL error: You have an error in your SQL syntax

MySQL error: You have an error in your SQL syntax

Author

Date

Category

Recently I had to work with MySQL. Wrote a line like this in php:

$ query = "SELECT 'catalog' FROM $ moduls WHERE posit = 'head'";

Upon request, it outputs:

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 ‘WHERE posit =’ head ” at line 1


Answer 1, authority 100%

the name of the table in MySQL (I’m not sure about the other databases) is taken not in single quotes, but in an apostrophe which is in Russian. And in quotes it is a string

$ query = "SELECT` catalog` FROM ". $ moduls." WHERE posit = 'head' ";

Answer 2, authority 94%

$ query = "SELECT catalog FROM". $ moduls. "WHERE posit = 'head'";

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions