0

Not able to find what is the error in this MySQL query.

Error : #1064 - 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...

CREATE TABLE IF NOT EXISTS `files` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `root` varchar(255) NOT NULL,
  `name` text NOT NULL,
  `slug` text NOT NULL,
  PRIMARY KEY (`id`)
)

INSERT INTO 'files' ('root', 'name') VALUES ('jvfs2rbpmasor7','Boxes_Teal.png');

2 Answers 2

1

You are using quotes for your table names which is invalid, should use ` back tick

INSERT INTO `files` (`root`, `name`) VALUES ('jvfs2rbpmasor7','Boxes_Teal.png');

You are using PHP so you should use functions which will throw you friendly errors to debug your query, like

if(!$query) echo 'Error '.mysqli_error($connection);
Sign up to request clarification or add additional context in comments.

2 Comments

@CODESEEK Yes it will, you have to use back ticks if you use mysql reserved keywords as column names(which you should avoid always), so backticks in your query won't harm,its just like an extra secirity
Never use backticks. They are just one more way for you to make syntax errors. The only reason you need them is if you have a column name that is a reserved word, and using column names that are reserved words is a terrible idea as well, so that's two bad habits you can avoid at once.
1

The issue is, I believe, that when you are specifying table names and column names, you should use backticks (`).

Solution:

Change the following line:

INSERT INTO 'files' ('root', 'name') VALUES ('jvfs2rbpmasor7','Boxes_Teal.png');

...to:

INSERT INTO `files` (`root`, `name`) VALUES ('jvfs2rbpmasor7','Boxes_Teal.png');

1 Comment

Thanks. @Ben Pearl Kahan

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.