ULX

Author Topic: Error in External MySQL database config - bad key  (Read 101 times)

0 Members and 1 Guest are viewing this topic.

Offline jacksop

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
Error in External MySQL database config - bad key
« on: January 13, 2020, 04:29:56 AM »
Hey!
So I have connected my server to an external mysql database using the mysqloo9 module and have populated it with information such as player steamids.
I also want to log the ULX rank/user group on this database to help keep track, however I have run into an issue with the code.

Here is the code:

Code: [Select]
function DBULXRank (ply, currentulxrank)
local query2 = DB_RP:query( "SELECT ulx_rank FROM playerinformation WHERE steam_id = '" .. ply:SteamID() .. "';") -- checking current data

query2.onSuccess = function()

if (#query2:getData() != ply:GetUserGroup()) then -- if the data does not equal the in-game usergroup
local query = DB_RP:query("UPDATE playerinformation SET ulx_rank = '".. currentulxrank .."' WHERE steam_id = '" .. ply:SteamID() .. "';") --update the database column called ulx_rank
query.onSuccess = function()
MsgC( Color (0, 0, 255), "[SQL] The new player's rank " .. currentulxrank .. " was logged! \n")
end
query.onError = function(db, err)
MsgC( Color (255, 0, 0), "[SQL] (Add Player) - Error: ", err)
end
query:start()
end
end
query2:start()
end

hook.Add("PlayerInitialSpawn", "UpdateULXrole", function(ply)
DBULXRank(ply:GetUserGroup())
end)

What I want this function to do is when the player spawns in/connects, i want to check the database if the ULX rank is the correct one that is in-game, if not then update it.

The error is:

attempt to index a string value with bad key ('SteamID' is not part of the string library)

How can I fix this? Let me know if you need more information.
Please keep in mind that I am new to lua so if theres an obvious problem please let me know how to solve it!
Thanks in advance


Offline jacksop

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
Re: Error in External MySQL database config - bad key
« Reply #1 on: Today at 01:18:54 AM »
Based on some testing I did, the cause of this problem is when I try to retrieve and concatenate ply:SteamID.
I am assuming the error: "attempt to index a string value with bad key" means I cannot concatenate this value as a string but rather as a variable.
So i changed my query line to this:
Code: [Select]
local query2 = DB_RP:query( "SELECT ulx_rank FROM playerinformation WHERE steam_id = '" .. ply:SteamID() "';")         -- no dots after ply:SteamID()

Doing so gives me this error instead: attempt to call a string value

So I guess my ultimate question here is.. how does lua respond to what value the ply:SteamID() is? is a treated as a variable? string?
Am I on the right track here or just going off on pointless tangents?  :D :-\