PHP create table error 1064

旧城冷巷雨未停 提交于 2019-11-29 18:37:29

You need to escape int1 and int2. They are reserved words in MySQL

CREATE TABLE Bookings 
(
    id int(6) NOT NULL auto_increment, 
    name varchar(25),
    email varchar(35),
    number varchar(20),
    buffet varchar(3),
    ceilidh varchar(5),
    work1 varchar(3),
    beg1 varchar(3),
    `int1` varchar(3),
    adv1 varchar(3),
    youth varchar(3),
    lunch varchar(3),
    beg2 varchar(3),
    `int2` varchar(3),
    adv2 varchar(3),
    dinner varchar(3),
    dance varchar(5),
    work2 varchar(3),
    lunch2 varchar(3),
    price varchar(5),
    PRIMARY KEY  (ID)
)

You have problem with your column name(s)

int1s varchar(3),

and

int2 varchar(3),

change that to something else or enclose them in backticks.

Like this...

CREATE TABLE Bookings 
(
id int(6) NOT NULL auto_increment, 
name varchar(25),
email varchar(35),
number varchar(20),
buffet varchar(3),
ceilidh varchar(5),
work1 varchar(3),
beg1 varchar(3),
`int1` varchar(3), /* see here... */
adv1 varchar(3),
youth varchar(3),
lunch varchar(3),
beg2 varchar(3),
`int2` varchar(3), /* see here... */
adv2 varchar(3),
dinner varchar(3),
dance varchar(5),
work2 varchar(3),
lunch2 varchar(3),
price varchar(5),
PRIMARY KEY  (ID)
)

You are using reserved words for column names. Check the following link to the mysql reference:

http://dev.mysql.com/doc/refman/5.7/en/reserved-words.html

Do not use any reserved words for column names. You need to change the column name int1 and int2 as they are reserved words. For more reserved words please see the link provided by @Alex Vogt.

You need to understand the difference between PHP and SQL.

You cannot put everything between <?php and ?> into mysql. This is the PHP part. In PHP you will connect to a MYSQL server and send a query to that server. I think you did take everything, because your error specifies near '$user = "root"' at line 1

If you want to test your query, only take the part between $query = " and "; and paste that in mysql to test the query.

So that would only be this part:

CREATE TABLE Bookings 
(
id int(6) NOT NULL auto_increment, 
name varchar(25),
email varchar(35),
number varchar(20),
buffet varchar(3),
ceilidh varchar(5),
work1 varchar(3),
beg1 varchar(3),
int1 varchar(3),
adv1 varchar(3),
youth varchar(3),
lunch varchar(3),
beg2 varchar(3),
int2 varchar(3),
adv2 varchar(3),
dinner varchar(3),
dance varchar(5),
work2 varchar(3),
lunch2 varchar(3),
price varchar(5),
PRIMARY KEY  (ID)
)

Once you do that, juergen d's answer might apply: escape int1 and int2 by changing them into `int1` and `int2` to escape reserved keywords.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!