XJTRy Posted February 16, 2008 Share Posted February 16, 2008 The following script works correctly and will create a new table in the database. However, when I add an AUTO_INCREMENT to the Id field it will fail to create. The exact wording I've tried is as follows "Id int(6) NOT NULL AUTO_INCREMENT ," Was hoping someone could help me correct this. Thanks. $query = 'SELECT DATABASE db233024213'; $result = mysql_query($query); mysql_select_db("db233024213"); $query = "CREATE TABLE user ( Id int(6) NOT NULL , <-----------------------------This is where I put the wording above which fails the script Date varchar(15) NOT NULL, Acmod varchar(15) NOT NULL, Acid varchar(10) NOT NULL, Legs varchar(10) NOT NULL, Route varchar(30) NOT NULL, Duration varchar(10) NOT NULL, Dl varchar(15) NOT NULL, Nl varchar(10) NOT NULL )"; $result = mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/91437-adding-auto-increment-kills-table-creation/ Share on other sites More sharing options...
dingus Posted February 17, 2008 Share Posted February 17, 2008 ok firstly i beleave that the auto_increment is accauly case sensitive (like most things) try this Id int(6) NOT NULL auto_increment, i also recommend adding this to the bottom PRIMARY KEY (Id) so the finished code should look like this $query = 'SELECT DATABASE db233024213'; $result = mysql_query($query); mysql_select_db("db233024213"); $query = "CREATE TABLE user ( Id int(6) NOT NULL , <-----------------------------This is where I put the wording above which fails the script Date varchar(15) NOT NULL auto_increment, Acmod varchar(15) NOT NULL, Acid varchar(10) NOT NULL, Legs varchar(10) NOT NULL, Route varchar(30) NOT NULL, Duration varchar(10) NOT NULL, Dl varchar(15) NOT NULL, Nl varchar(10) NOT NULL PRIMARY KEY (Id) )"; $result = mysql_query($query); reason for the last line is because i think mysql will only accept auto increment if it is auto number (but don't quote me i might have that ass about) Link to comment https://forums.phpfreaks.com/topic/91437-adding-auto-increment-kills-table-creation/#findComment-468540 Share on other sites More sharing options...
Stooney Posted February 17, 2008 Share Posted February 17, 2008 dingus put the auto increment on the wrong line: $query = 'SELECT DATABASE db233024213'; $result = mysql_query($query); mysql_select_db("db233024213"); $query = "CREATE TABLE user ( Id int(6) NOT NULL auto_increment, Date varchar(15) NOT NULL, Acmod varchar(15) NOT NULL, Acid varchar(10) NOT NULL, Legs varchar(10) NOT NULL, Route varchar(30) NOT NULL, Duration varchar(10) NOT NULL, Dl varchar(15) NOT NULL, Nl varchar(10) NOT NULL PRIMARY KEY (Id) )"; $result = mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/91437-adding-auto-increment-kills-table-creation/#findComment-468557 Share on other sites More sharing options...
XJTRy Posted February 18, 2008 Author Share Posted February 18, 2008 This worked! Thanks. Link to comment https://forums.phpfreaks.com/topic/91437-adding-auto-increment-kills-table-creation/#findComment-469799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.