Adam Miller
Adam Miller

Reputation: 23

"Incorrect table definition" when trying to CREATE TABLE

I am trying to create a table in a php script and I am getting an SQL error. I can't find it or figure out how to fix it. I do have $table defined earlier in the script. Thanks in advance!

$newtable = "CREATE TABLE $table (id INT(11) NOT NULL AUTO_INCREMENT, time datetime NOT NULL,punchtype VARCHAR(255) NOT NULL,groupname VARCHAR(255) NOT NULL, dept VARCHAR(255) NOT NULL, notes VARCHAR(255))";

Error Message: Incorrect table definition; there can be only one auto column and it must be defined as a key

Upvotes: 0

Views: 59

Answers (1)

MH2K9
MH2K9

Reputation: 12039

try this, it works

$newtable = "CREATE TABLE $table
(id INT(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
time datetime NOT NULL,
punchtype VARCHAR(255) NOT NULL,
groupname VARCHAR(255) NOT NULL,
dept VARCHAR(255) NOT NULL,
notes VARCHAR(255))";

Upvotes: 1

Related Questions