我无法在mysql数据库中创建我的表

时间:2013-05-13 08:20:55

标签: php mysql phpmyadmin

这段代码有什么问题?当我运行这个PHP代码时,资源管理器显示错误。

    mysql_query("CREATE TABLE user( 
username VARCHAR(10) NOT NULL, 
PRIMARY KEY(username), 
name VARCHAR(20) NOT NULL, 
family VARCHAR(35) NOT NULL, 
graduate INT(1) NOT NULL,
single INT(1) NOT NULL,
children INT(1),
address VARCHAR, 
father VARCHAR(20) NOT NULL, 
birthday INT NOT NULL,
start INT(50),
grade int(1) NOT NULL, 
unit VARCHAR(20) NOT NULL,
manager VARCHAR(10),
mobile VARCHAR(13), 
officetell VARCHAR(13), 
tell VARCHAR(13),
email VARCHAR(100),
sex INT(1) NOT NULL)") 
or die(mysql_error()); 

4 个答案:

答案 0 :(得分:1)

我认为问题在于:

address VARCHAR,

您应该指定自VARCHAR类型以来地址字段的最大长度:

address VARCHAR(255),

答案 1 :(得分:0)

它会起作用:

       mysql_query("CREATE TABLE user( 
username VARCHAR(10) NOT NULL, 
PRIMARY KEY(username), 
name VARCHAR(20) NOT NULL, 
family VARCHAR(35) NOT NULL, 
graduate INT(1) NOT NULL,
single INT(1) NOT NULL,
children INT(1),
address VARCHAR(20), 
father VARCHAR(20) NOT NULL, 
birthday INT NOT NULL,
start INT(50),
grade int(1) NOT NULL, 
unit VARCHAR(20) NOT NULL,
manager VARCHAR(10),
mobile VARCHAR(13), 
officetell VARCHAR(13), 
tell VARCHAR(13),
email VARCHAR(100),
sex INT(1) NOT NULL)") 
or die(mysql_error()); 

答案 2 :(得分:0)

你可以试试这个:

mysql_query("CREATE TABLE user( 
username VARCHAR(10) NOT NULL, 
PRIMARY KEY(username), 
name VARCHAR(20) NOT NULL, 
family VARCHAR(35) NOT NULL, 
graduate INT(1) NOT NULL,
single INT(1) NOT NULL,
children INT(1),
address VARCHAR(50), 
father VARCHAR(20) NOT NULL, 
birthday INT NOT NULL,
start INT(50),
grade int(1) NOT NULL, 
unit VARCHAR(20) NOT NULL,
manager VARCHAR(10),
mobile VARCHAR(13), 
officetell VARCHAR(13), 
tell VARCHAR(13),
email VARCHAR(100),
sex INT(1) NOT NULL)") 
or die(mysql_error()); 

这是代码中的问题:地址VARCHAR

CHAR和VARCHAR类型的声明长度表示您要存储的最大字符数。例如,CHAR(30)最多可以包含30个字符。

参考:http://dev.mysql.com/doc/refman/5.0/en///char.html

答案 3 :(得分:0)

您忘记了ADDRESS的尺寸:

address VARCHAR(<size>)