Hello. I'm currently working on a database system, and I cant seem to get this code to be a string:
[CODE]local UserRank = db:query("SELECT Rank FROM gm_players WHERE SteamID = '" .. ply:SteamID() .. "'")[/CODE]
Code where it's used:
[CODE]function FirstJoinMysql( ply )
UserGroup = ply:GetUserGroup()
local query1 = db:query("SELECT * FROM gm_players WHERE SteamID = '" .. ply:SteamID() .. "'")
local UserRank = db:query("SELECT Rank FROM gm_players WHERE SteamID = '" .. ply:SteamID() .. "'")
query1.onSuccess = function(q)
if not checkQuery(q) then
local query2 = db:query("INSERT INTO gm_players(SteamID, Credits, Rank) VALUES ('" .. ply:SteamID() .. "', " .. 0 .. ", " .. UserGroup .. ")")
query2.onSuccess = function(q) print("New user. Making database tables...") end
query2.onError = function(q,e) print("Something went wrong making the database tables") end
query2:start()
else
if(UserGroup == UserRank) then
print("MySQL group is equal to Server group")
else
print("MySQL group is not equal to Server group! Correcting...")
print( Query1 )
end
end
end
query1.onError = function(q,e) print("Something went wrong when checking") end
query1:start()
end
hook.Add( "PlayerAuthed", "PlayerAuthed", FirstJoinMysql )[/CODE]
That's where it would execute the string.
Do [lua]local _query = "SELECT Rank FROM gm_players WHERE SteamID = '" .. ply:SteamID() .. "'"
local _result = db:quert( _query );[/lua]
or so... If I'm understanding you correctly? Also, make sure to always escape input..
That would do the same thing, just in 2 lines? Wouldn't it?
What do you mean you can't get it to be a string? Do you get any errors? (and localize FirstJoinMySQL function).
I tried to put this to solved, couldn't.
I found a solution:)
[CODE]local query1 = db:query("SELECT * FROM Players WHERE SteamID = '" .. ply:SteamID() .. "'")[/CODE]
...
[CODE]local rank = query1:getData()[1]["Rank"][/CODE]
Sorry, you need to Log In to post a reply to this thread.