#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    66
    Rep Power
    15
    Hi, I've got a little script that takes some info from users and adds it to a db. On the db, I have a field called "ID" which auto-increments and is the primary key.

    How should I write my "insert into..." to account for this?

    I have it set up like this:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>$query = "INSERT INTO users VALUES('','$username','$password', '$email')";[/quote]
    ... but my table is not being updated.

    ~ AoErat
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    66
    Rep Power
    15
    I've changed the line to this:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>$query = "INSERT INTO users (ID, username, password, email) VALUES('','$username','$password', '$email')";[/quote]

    This is how phpMyAdmin does it (where it does work), but it still doesn't work in my script.
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    $query = "INSERT INTO users (ID, username, password, email) VALUES(null,'$username','$password', '$email')";

    Notice there are no quotes around null.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    61
    Rep Power
    15
    I use the same method you use with the empty double quotes for my auto_incrementing column. Not sure why it doesn't work, maybe try putting a semicolon at the end there.
  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,646
    Rep Power
    4492
    If none of those are working, just leave ID out entirely. It'll update automatically.

    $query = "INSERT INTO users (username, password, email) VALUES('$username','$password', '$email')";

    ---John Holmes...
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    66
    Rep Power
    15
    Thanks guys.

    I've got this working now.

Similar Threads

  1. Easiest way to create an auto incrementing column?
    By jpenn in forum Firebird SQL Development
    Replies: 5
    Last Post: December 29th, 2006, 04:43 AM
  2. primary and foreign keys
    By jp1234 in forum Database Management
    Replies: 7
    Last Post: February 10th, 2004, 03:24 PM
  3. 3 primary keys.....?
    By cram81 in forum MySQL Help
    Replies: 4
    Last Post: December 29th, 2003, 03:44 PM
  4. composite primary keys
    By tamara in forum MySQL Help
    Replies: 1
    Last Post: July 17th, 2003, 02:28 AM
  5. Reclaim deleted primary keys?
    By webdesign123now in forum MySQL Help
    Replies: 3
    Last Post: December 1st, 2002, 12:12 AM

IMN logo majestic logo threadwatch logo seochat tools logo