3

When using the following code:

CREATE TABLE stats 
(
  username varchar(12), 
  starting text, 
  ending text, 
  UNIQUE (username)
)

OR

CREATE TABLE stats 
(
  username varchar(12), 
  starting text, 
  ending blob, 
  UNIQUE (username)
)

I get an error message:

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 'starting text, ending text, UNIQUE (username))' at line 1

Am I doing something wrong? It worked perfectly fine before adding ending text inside the query.

glglgl
  • 85,390
  • 12
  • 140
  • 213

3 Answers3

5

starting is a reserved word, therefore you need to write it like this:

`starting` text
Andreas Ågren
  • 3,701
  • 23
  • 32
  • Thanks! Would I need to use it for all queries? Such as: `mysql_query("INSERT IGNORE INTO stats (username, starting, ending) VALUES ('$username', '$stats', '$stats')");` –  Aug 09 '11 at 07:48
  • yes, otherwise you will get complaints about it like the one above. – glglgl Aug 09 '11 at 07:50
1

starting is a reserved word in MySQL; therefore you either should take a different one or enclose it in `backticks`.

CREATE TABLE stats 
(
  username varchar(12), 
  xyzstarting text, 
  ending text, 
  UNIQUE (username)
)

works for me.

glglgl
  • 85,390
  • 12
  • 140
  • 213
1

starting is a reserved keyword

CREATE TABLE stats 
(
  username varchar(12), 
  NotUsingStarting text, 
  ending text, 
  UNIQUE (username)
)
gbn
  • 408,740
  • 77
  • 567
  • 659