PHP创建表错误1064 [英] PHP create table error 1064

查看:95
本文介绍了PHP创建表错误1064的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在mySQL中创建一个表.这是我下面的php页面,当我运行该页面时没有错误,但是该表不在mySQL中,而当我在mySQL中测试代码时,我得到了错误

I am trying to create a table in mySQL. This is my php page below, when I run the page there are no errors but the table is not in mySQL and when I test the code in mySQL I'm getting the error

#1064-您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 在第1行的'$ user ="root"'附近.

#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 '$user = "root"' at line 1.

我已经对该错误的含义进行了一些研究,但我无处可寻.我真的不明白这是什么意思.老实说,我不太了解php,而只是改编我以前的uni教程中编写的代码.请帮忙.

I've done a bit of research into what this error means but I'm getting no where. I don't really understand what it means. If I'm honest I don't really understand php I'm just adapting the code I've written in previous uni tutorials. Please help.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php 
$user="root"; 
$password=""; 
$database="test"; 

mysql_connect('localhost',$user,$password)or die( "Unable to connect to server");
mysql_select_db($database) or die( "Unable to select database");
$query="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)
)";

mysql_query($query); 
mysql_close(); 

?>
</body>
</html>

推荐答案

您需要转义int1int2.它们是 MySQL中保留的单词

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)
)

这篇关于PHP创建表错误1064的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆