0

i programm some PHP Scripts and i wrote this sql query (for example):

INSERT INTO \`table1\` (\`article\`, \`typ\`)
    VALUES(\`test\`, \`test2\`)

this query works.

my problem is that if i write the tablename and columns like this 'table1' i get an sql error: SQL Error(1064): You have an error in your SQL Syntax; check the manual that corresponds to your MariaDB server Version for the right syntax to use near ''article', 'typ') VALUES('test', 'test1')'

Does anybody know why i have to write it like this `table1` and why it doesnt work with normal --> ' ?

Server-Typ: MariaDB

Server-Version: 10.1.9-MariaDB - mariadb.org binary distribution

Server-Zeichensatz: UTF-8 Unicode (utf8)

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Mark
  • 40
  • 1
  • 8

1 Answers1

1

The right way to write the code is:

INSERT INTO table1(article, typ)
    VALUES ('test', 'test2')

All of the identifiers (table and column names) are valid names. They do not need to be escaped. Hence, no backticks are necessary.

You do need single quotes for quoted strings, not backticks. If the backticks are part of the name, you could just do:

INSERT INTO table1(article, typ)
    VALUES ('`test`', '`test2`');

But that seems highly unlikely.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • i'm so sorry.... i made the backticks because in preview i cant see the ' codes okay, i don't need the ' at the column names. i tried it and it works, thx so much and sorry for my stupid question. so simple... omg... – Mark Feb 12 '17 at 18:51