我用  $cb=mysql_query("CREATE TABLE `".$tb."` (id int not null auto_increment,content varchar(400),date datetime)");  新建一个表,但是报错:   Incorrect table definition; there can be only one auto column and it must be defined as a key
我把每个字段后的参数只改为一个,可以正确建表,但我要建一个自增的ID,该怎么办?

解决方案 »

  1.   


    CREATE TABLE  `test`.`test` (
    `int` INT NOT NULL AUTO_INCREMENT ,
    `content` VARCHAR( 400 ) NOT NULL ,
    `addtime` DATETIME NOT NULL ,
    PRIMARY KEY (  `int` )
    ) ENGINE = INNODB;
    给ID加个主键就可以了! Incorrect table definition; there can be only one auto column and it must be defined as a key
    的意思是
    如果你把一个字段当作auto increment
    比必须把这个字段作为索引(key)
      

  2.   

    问题解决了,谢谢高手!!不过又有新问题了:
    $table=$_COOKIE[logging];
    $table=str_replace("@"," ",$table);
    $table=str_replace("."," ",$table);
    $sql=mysql_query("insert into `".$table."` (content,date) values ('$_POST[content]',now())")or die("".mysql_error());
    不知道我该怎样写这句insert语句,因为我是把表名当变量处理的,无论我怎么改都没用,
      

  3.   

    还有这句也一样:
    $count=mysql_query("select count(*) from `".$table."`")or die("".mysql_error());
    求助啊