- - Readme First! Read and follow the rules, otherwise your posts will be closed
There are currently, 331 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 [ ]
Joined: Dec 15, 2005
Tue Dec 20, 2005 7:42 am
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?
Joined: Mar 14, 2004
Location: Florida, USA, Earth, Space
Tue Dec 20, 2005 10:43 am
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.
_________________ - Prophet
Get the Last Visit module (and others modules I designed) from my website! FREE! http://jasonlau.biz
Joined: Dec 15, 2005
Tue Dec 20, 2005 8:27 pm
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
cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum