• updating a database entry
    2 replies, posted
I'm currently working on a forum to server and server to forum rank database sync. I have the forum to server aspect working, but I'm struggling on the server to forum aspect. Here is my current attempt to a server to forum: [code] function SaveUpdatedRank(ply) local query1 = db2:query("SELECT * from `tobiasx_mybb_users` WHERE `loginname` = '"..ply:SteamID64().."';") query1.onData = function(q, d) query1.onSuccess = function(q) if (ply:GetUserGroup() == "owner" && d.usergroup != 10) then local editgroup = db2:query("REPLACE INTO `tobiasx_mybb_users` SET `loginname`='"..ply:SteamID64().."', `usergroup`='10';") editgroup:start() end end end query1.onError = function(Q,E) ServerLog("Failed to load player rank! Error: ") print(E) end query1:start() end hook.Add("PlayerDisconnected", "UpdatePlayerForumULXRank", SaveUpdatedRank) [/code] I'm probably doing it completely wrong, so can someone please explain to me how to do it correctly? Thank you.
Personally I'd just use UPDATE not REPLACE INTO. Not really sure what REPLACE INTO does. loginname is a unique index, no? You should be SETting usergroup WHERE loginname = ? I would imagine. I don't think you even need the first query.
[QUOTE=RealDope;49440470]Personally I'd just use UPDATE not REPLACE INTO. Not really sure what REPLACE INTO does. loginname is a unique index, no? You should be SETting usergroup WHERE loginname = ? I would imagine. I don't think you even need the first query.[/QUOTE] That worked, thank you!
Sorry, you need to Log In to post a reply to this thread.