Hi,

I've been working a while on a new website for my student society using drupal.
Because we already have a user database with passwords, usernames etc. from our old website,
we just want to quickly put these into the drupal database.

I wrote a piece of php code to quickly load this old data into the new drupal database.
The data is now in the new database, but i think some essential data is missing:
Drupal doesnt recognise the inserted users as drupal users.

I.E. if I want to add a new user to the database (using register, or the admin panel), drupal just looks up the max(uid) and then returns a uid that is already taken by a inserted user. Then it sends the email to the email-adress, you just entered while registering, and you get 2 links.
The first one says: you can log in here and here with your given username and password, but when you do drupal returns: username doesnt exist.
The other gives a one-time-link where you can alter the data you just entered. When you click that it gives all data, earlier inserted by my php-script, that is known with that already taken uid.

So if I register username: "test" with email: "test@test.com". Drupal finds uid "2" that already has data with username: "foobar" and email "foo@bar.com".
After registering it sends a confirmation email to "test@test.com" containing username:"test".
Then if I want to login using my new account username: "test", drupal can't find the username, because in the database uid "2" is still username "foobar".
If I click the one-time-link, the page says: this is a one time link for username "foobar". And then supplies al the information I entered for username "test" while registering except for the username that is still "foobar" and the emailadress that is "foo@bar.com".

The thing were it's going wrong, is that drupal finds uid "2" as the not yet registered uid. While there is already a user with uid 2. So probably drupal searches for more data then just uid, but also checks for ????

My question is:
What does it check more for, in order to decide which uid is the uid that hasnt been used yet?

Comments

migs87’s picture

I found the problem.

Instead of doing a sql check using "SELECT max(uid) FROM {users}" to get the uid for a new user.
Drupal checks for the next uid in the table {sequences} for {users}_uid.
So if you add 1000 users, apart from the root, be sure to change the {users}_uid value to 1000 + 1!
Else you'll get problems like the one sketched above!

Ciao

gcassie’s picture

I've had to create users directly a few times before. I've had better luck using the user_save function over direct database inserts. It will manage all the database and module hooks for you.