Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    762

    sql table code giving unknown error

    hi everyone,

    i was just trying to create these tables and i keep getting error message saying

    #1067 - Invalid default value for 'id'
    this is the sql code im trying to run

    PHP Code:
    CREATE TABLE users(

    id int10 ) DEFAULT '0' NOT NULL AUTO_INCREMENT ,
    username varchar40 ) ,
    PASSWORD varchar50 ) ,
    regdate varchar20 ) ,
    email varchar100 ) ,
    website varchar150 ) ,
    location varchar150 ) ,
    show_email int) DEFAULT '0',
    last_login varchar20 ) ,
    PRIMARY KEY id 

    So, where exactly im i going wrong?

  2. #2
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783
    I may be wrong, but give this a try:

    Make sure you are connected to your DB..
    PHP Code:
    $result "CREATE TABLE users
    (
    id INT(10) DEFAULT '0' AUTO_INCREMENT, 
    username VARCHAR(40), 
    PASSWORD VARCHAR(50), 
    regdate VARCHAR(20), 
    email VARCHAR(100), 
    website VARCHAR(150), 
    location VARCHAR(150), 
    show_email int(2) DEFAULT '0', 
    last_login VARCHAR(20), 
    PRIMARY KEY (id)
    )"
    ;
    $query $mysql_query($result) or die(mysql_error()); 
    Then on your page or script just call upon $query

    As for you row "id" you wouldnt really need to say "not null" since basically you are giving the person / object an id # when you add them 'auto_increment'

    Good Luck

  3. #3
    Join Date
    Jan 2003
    Posts
    1,715
    A default value is nonsensical on an auto-increment field with a unique key. Just this will be fine:
    id int( 10 ) NOT NULL AUTO_INCREMENT
    Game Servers are the next hot market!
    Slim margins, heavy support, fickle customers, and moronic suppliers!
    Start your own today!

  4. #4
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    762

    Thumbs up

    Originally posted by hiryuu
    A default value is nonsensical on an auto-increment field with a unique key. Just this will be fine:
    id int( 10 ) NOT NULL AUTO_INCREMENT
    the above suggestion worked great. Thank you very much.

    Also, platinumn23, thank you too. But sorry i couldnt try your method, as i lack knowledge of mysql.

    tc, bye

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •