• SQL Syntax Error
    3 replies, posted
So, I have a MySQL data saving function, and this gives me the error "near "SET": syntax error". What syntax am I misusing? Also, is this the best/most efficient way to save data like this? I did it this way to make it fully modular. [lua] function StoreData(object, ply, value) local r = sql.Query("SELECT "..object.." FROM Players WHERE steam = '"..sql.SQLStr(ply:SteamID()).."'") if r then sql.Query("UPDATE Players SET "..object.." = '"..sql.SQLStr(value).."' WHERE steam = '"..sql.SQLStr(ply:SteamID()).."'") if sql.LastError() then ply:ChatPrint(sql.LastError().." + UPDATE - Report this to an admin.") end else sql.Query("UPDATE Players SET "..object.." = '"..sql.SQLStr(value).."' WHERE steam = '"..sql.SQLStr(ply:SteamID()).."'") if sql.LastError() then ply:ChatPrint(sql.LastError().." + INSERT - Report this to an admin.") end end end [/lua]
Try print the whole, [LUA] print( "UPDATE Players SET "..object.." = '"..sql.SQLStr(value).."' WHERE steam = '"..sql.SQLStr(ply:SteamID()).."'" ); [/LUA]
[QUOTE=Busan1;42414230]Try print the whole, [LUA] print( "UPDATE Players SET "..object.." = '"..sql.SQLStr(value).."' WHERE steam = '"..sql.SQLStr(ply:SteamID()).."'" ); [/LUA][/QUOTE] UPDATE Players SET kills = '"1"' WHERE steam = '"STEAM_0:0:38907838"' UPDATE Players SET points = '"2"' WHERE steam = '"STEAM_0:0:38907838"'
Don't use ' with the [I]sql.SQLStr[/I] function, it automatically adds quotes around them.
Sorry, you need to Log In to post a reply to this thread.