The point is, you can only estimate what the next id will be for a given statement, because 2 queries can fire simultaneously, and you could have the id mixed up.
In enterprise grade db, we don't use an auto-increment in this case, but what is known as a sequence.
You can replicate it easily in mysql too, in fact, but you will need to be careful upon your insert queries in the future if you go that way.
A sequence is just a counter, with a start value and a step increment.
In db like postgresql, when you want an id with a "like auto-increment" behavior, you use them, with a default value as the next sequence number.
In short, the easiest and most sure way to go is to keep a sequence on your own:
Code:
create table sequences (
seqId int not null auto-increment,
seqName varchar(100) not null,
seqStep int default 1,
seqVal int default 0,
primary key (seqId)
);
Then, declare your sequences:
Code:
insert into sequences (seqName) values ('members');
And now, next time you want to insert a member, start by getting and reserving the next id:
PHP Code:
function nextVal($seqName=FALSE){
if($seqName===FALSE){
return FALSE;
}
$q="select seqVal+seqStep as nextVal from sequences where seqName='$seqName'";
$res=mysql_query($q);
while($o=mysql_fetch_object($res)){
$ret=$o->nextVal;
mysql_query("udpate sequences set seqVal=$ret where seqName='$seqName'");
return $ret;
}
}
Now, a call to the php nextVal() function will return you the next id to use, and increment the counter value, effectively reserving it.
Now, you only have to use that value when you insert your users profile.
This way, you know you won't have clashes between simultaneous requests, and you will know the id that the user will get before creating his profile.