- - Readme First! Read and follow the rules, otherwise your posts will be closed
There are currently, 163 guest(s) and 0 member(s) that are online. You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - Some SQL troubles
Some SQL troubles
Posted: Tue Dec 20, 2005 7:42 am Post subject: Some SQL troubles
Hey guys... I'm sure I'm making some noob mistake with this, it's been years since I've done much coding, but any help I could get would be greatly appreciated
I'd trying to fill in a few extras tables when a user verifies their account. I hunted down
$db->sql_query("INSERT INTO ".$user_prefix."_users (user_id, username, user_email, user_password, user_avatar, user_avatar_type, user_regdate, user_lang) VALUES (NULL, '$row[username]', '$row[user_email]', '$row[user_password]', 'gallery/blank.gif', 3, '$row[user_regdate]', '$language')");
$db->sql_query("DELETE FROM ".$user_prefix."_users_temp WHERE username='$username' AND check_num='$check_num'");
in the modules/Your_Account/index.php file, and afterwards added
$db->sql_query("INSERT INTO eqdkp_users (user_id, username, user_password, user_email, user_alimit, user_elimit, user_ilimit, user_nlimit, user_rlimit, user_lang, user_style, user_key, user_lastvisit, user_lastpage, user_active, user_newpassword) VALUES (NULL, '$row[username]', '$row[user_password]', '$row[user_email]', 100, 100, 100, 10, 100, 11, 'english', NULL, 0, NULL, '1', NULL)");
This part works fine. What I want to do next is giving me some problems. I want to pull the user_id out of the eqdkp_users table for the record I just created, and then create an entry in the eqdkp_auth_users table that includes it.
First, I tried
$dkpid = $db->insert_id();
$db->sql_query("INSERT INTO eqdkp_auth_users (user_id, auth_id, auth_setting) VALUES ('$dkpid', 25, 'Y')");
No luck. It still inserted values into the table, but always used a user_id of 0. I then tried replacing the insert_id with
$dkpid = $db->sql_query("SELECT user_id FROM eqdkp_users WHERE username = '$username'");
and still get the same issue - it inserts a record, but always uses 0 as the user_id.
Any idea what I'm missing here?
Location: Florida, USA, Earth, Space Posted: Tue Dec 20, 2005 10:43 am Post subject:
Try this after the user has been inserted ...
$result = $db->sql_query("SELECT user_id FROM eqdkp_users ORDER BY user_id DESC");
$row = $db->sql_fetchrow($result);
$last_id = $row[user_id];
Then use $last_id wherever it's needed.
Posted: Tue Dec 20, 2005 8:27 pm Post subject:
Thanks Prophet, worked like a charm!
And with that, the last of my "high priority - must complete before going live" tasks is scratched off the list
All times are GMT - 8 Hours
© 2001,2002 phpBB Group