Jump to content

Adding Auto Increment kills table creation.


XJTRy

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.