Jump to content

setting 'auto increment' primary keys


roll_or_die

Recommended Posts

im trying to use phpmyadmin in XAMPP to be able to set a primary key field as an id column so that whenever a user registers on my site; they are automatically assigned an id number.i cant seem to be able to do it though, i set it to 'auto increment' and int with a length of 15, but i cant figure out how to make it so that each user is automatically assigned a number upon registering?

Link to comment
Share on other sites

im trying to use phpmyadmin in XAMPP to be able to set a primary key field as an id column so that whenever a user registers on my site; they are automatically assigned an id number.i cant seem to be able to do it though, i set it to 'auto increment' and int with a length of 15, but i cant figure out how to make it so that each user is automatically assigned a number upon registering?
well i guess you'd have to post us your php code for the register function for us to help you out, you are giving us too little information to work on. just do an INSERT with the propper values and that should work, taking into consideration the auto_inc.- miffe
Link to comment
Share on other sites

When you have already assigned auto_increment, the all you need is to insert the data into the table and it should work....When you insert data, just dont give any value to the ID field...example:tableID Fname Mname Lname(auto)Your insert statement should be.... Did you try it like this? and does it still not work?INSERT INTO tblname (fname,mname,lname) VALUES ('val1','val2','val3')

Link to comment
Share on other sites

  • 1 month later...

Another long-shot to use is to find the "max" value of all the ID column, then using whatever application INSERT the incremented-one value to it.Assuming using the auto_increment thingy we have 5 records with ID: 1, 2, 3, 4, 5 in order...We then (for whatever reason) delete record number 2 and 4, thus there are now 3 records: 1, 3, 5...Question:The next time we use INSERT with auto_increment constraint of function, will the new record go into ID number 2, or ID number 6? Just making sure we don't have child-data referencing to the wrong parent object with same ID.I prefer having the ID as uniqueidentifier or some-sort, that way it can also serves as an additional security--too long an ID for people to deal with.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...