If your inserting the information intoa database it's best to let your database due the work.
Set the field in the database to the following
INT
NOT NULL
UNIQUE
PRIMARY KEY
AUTO_INCREMENT
This will start your db at 1 9I know in MS SQL you can set the starting number as well)
Hope this helps