Jump to content

AUTO INC in PHP Table Creation


ShoeLace1291

Recommended Posts

Ok, I'm trying to make an installer but it says the sql syntax for my table creations code is wrong.  I think it has to do with the Auto Increment function.  This is my code:

 

$articles = "CREATE TABLE tech_articles ("
      . " articleID INTEGER(15) NOT NULL" 
      . ", authorID INTEGER(15) NOT NULL"
      . ", headline VARCHAR(50) NOT NULL"
      . ", articleContent TEXT NOT NULL"
      . ", datetimePosted DATETIME NOT NULL"
      . ")";

$admins = "CREATE TABLE tech_administrators ("
      . " userID INTEGER(15) NOT NULL AUTO INCREMENT" 
      . ", loginName VARCHAR(20) NOT NULL"
      . ", loginPass VARCHAR(80) NOT NULL"
      . ", userEmail VARCHAR(100) NOT NULL"
      . ")";

$comments = "CREATE TABLE tech_comments ("
      . " commentID INTEGER(15) NOT NULL AUTO INCREMENT" 
      . ", authorID INTEGER(15) NOT NULL"
      . ", articleID INTEGER(15)"
      . ", commentText TEXT NOT NULL"
      . ", datetimePosted DATETIME NOT NULL"
      . ")";

if (mysql_query($articles)) {
    print("Articles table created.\n");
  } else {
    print(mysql_error());
  }


if(mysql_query($admins)){
     print("Administrators table created.\n");
     } else {
        print(mysql_error());
}

if(mysql_query($comments)){
     print("Comments table created.\n");
     } else {
        print(mysql_error());
}

 

In the tech administrators table, I want userID to be auto increment.  Thanks for any help.

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.