Good afternoon,
I don't know if I just can't do this, or if I can, and I have it structured incorrectly.
What I'm trying to to is to generate a member table from a couple of imported excel spreadsheets.
To create the member records, I must assign a 'Username' for each individual member, which I am randomly generating.
but at the same time I need to make sure that I don't randomly generate any duplicate Usernames.
I was thinking I could do this, but can't seem to get it straight in my mind, and hoping someone could point me in the right direction...
$sql_s = "
SELECT name, address, city, state, zip, phone, email
FROM import_purchase_members
ORDER BY name
";
$result_s=mysql_query($sql_s);
while($request_s=mysql_fetch_array($result_s)){
// Split name into first and last
$name_parts = explode(" ", $request_s[0]);
// this is the part that is in question
// generate username
$username=genPswd();// function that creates 8 uppercase Alpha
// ### If a duplicate is created, generate a new username
while $username=(SELECT mem_id FROM members WHERE user = '$username';){
$username=genPswd();
}
// generate password
$pass=random_string();
$sql_i = "INSERT INTO members(mem_id, user, pass, pass2, email, status, company, fname, lname, addr1, addr2, city, state, zip, country, phone, cell, dsp_pref, join_date, last_update, prev_email, mem_status, sq_id, sq_answer, acceptance, bypass_purchase, skype) VALUES('', '$username', '" . md5($pass) . "', '', '$request_s[6]', 'I', '', '$name_parts[0]', '$name_parts[1]', '$request_s[1]', '', '$request_s[2]', '$request_s[3]', '$request_s[4]', '', '$request_s[5]', '', '1', now(), now(), '', 'F', 1, 'none', 'N', 'N', '')";
mysql_query($sql_i);
Any help would be greatly appreciated.
Douglas