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
https://forums.phpfreaks.com/topic/56103-auto-inc-in-php-table-creation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.