Serial key in Mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Heinz

    Serial key in Mysql

    Hi,
    can anyone tell me how I can automaticly generate a serial key? - I
    get an error message, when I don't provide a number for the id in the
    example below. A NULL value doesn't work either.
    Thank you very much for any hint.



    CREATE TABLE user
    (USER_ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
    USER_NAME varchar(10) NOT NULL,
    LAST_NAME varchar(30),
    FIRST_NAME varchar(30),
    E_MAIL varchar(30),
    M_PHONE varchar(15),
    PRIMARY KEY (USER_ID)
    );



    $query = "INSERT INTO user (USER_ID, USER_NAME, LAST_NAME, FIRST_NAME,
    E_MAIL, M_PHONE) VALUES
    ( $id, " .
    "\"" . $nick . "\", " .
    "\"" . $nachname . "\", " .
    "\"" . $vorname . "\", " .
    "\"" . $email . "\", " .
    "\"" . $handy . "\")";
  • Janwillem Borleffs

    #2
    Re: Serial key in Mysql

    Heinz wrote:[color=blue]
    > can anyone tell me how I can automaticly generate a serial key? - I
    > get an error message, when I don't provide a number for the id in the
    > example below. A NULL value doesn't work either.
    > Thank you very much for any hint.
    >[/color]

    USER_ID INT(11) AUTO_INCREMENT

    JW



    Comment

    • Janwillem Borleffs

      #3
      Re: Serial key in Mysql

      Janwillem Borleffs wrote:[color=blue]
      > USER_ID INT(11) AUTO_INCREMENT
      >[/color]

      Additionally:

      $query = "INSERT INTO user (USER_NAME, LAST_NAME[,...]

      (So, don't assign a value to USER_ID. Let MySQL handle this)


      JW



      Comment

      • Gary L. Burnore

        #4
        Re: Serial key in Mysql

        On Sun, 4 Jul 2004 13:12:34 +0200, "Janwillem Borleffs"
        <jw@jwscripts.c om> wrote:
        [color=blue]
        >Janwillem Borleffs wrote:[color=green]
        >> USER_ID INT(11) AUTO_INCREMENT
        >>[/color]
        >
        >Additionally :
        >
        >$query = "INSERT INTO user (USER_NAME, LAST_NAME[,...]
        >
        >(So, don't assign a value to USER_ID. Let MySQL handle this)[/color]

        If you're not explicitly populating fields, you still need to have a
        placeholder for it. If it's the first field in the table,

        insert into user ( 0, 'USER_NAME', 'USER LAST NAME'. ....) will get it
        right.
        --
        gburnore@databa six dot com
        ---------------------------------------------------------------------------
        How you look depends on where you go.
        ---------------------------------------------------------------------------
        Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
        | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
        DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
        | ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
        Black Helicopter Repair Svcs Division | Official Proof of Purchase
        =============== =============== =============== =============== ===============
        Want one? GET one! http://www.databasix.com
        =============== =============== =============== =============== ===============

        Comment

        Working...