• MySQL runing 8,000 times.
    1 replies, posted
For some reason, when i run my mysql auth script, and the player isnt in the database, and it trys to add them.... it adds them 8,000+ times, then there is an overflow. Can someone help me here? Thanks :D [lua] require("mysql") Msg("\n\n\n\nBegining of check.lua\n") local db, error = mysql.connect("localhost", "root", "hehehehe", "gmod_users"); if (db == 0) then Msg(error .. "\n") end function playerjoined(ply) Msg("Player "..ply:Nick().." joined the server.\n") for k, v in pairs (player.GetAll()) do v:PrintMessage(HUD_PRINTCENTER,"Welcome to the server "..ply:Nick().."! Your SteamID is "..ply:SteamID()..".") end SQLquery = "SELECT * FROM gmod_class WHERE steamid = '"..ply:SteamID().."'" Msg(SQLquery.."\n") query(SQLquery, ply) end function query(str, ply) Msg("Begining of query func\n") local table, success, error = mysql.query(db, str) if (not success) then Msg(tostring(error)) end if table[1] then Msg("Congratulations "..ply:Nick().."! You are in the database!\n") end if !table[1] then Msg("Sorry "..ply:Nick()..", you are not in the database.\n") AddPlayer(ply) end end Msg("EOF\n") hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", playerjoined ) function AddPlayer(ply) SQLquery = "INSERT INTO gmod_class (steamid, class) VALUES('"..ply:SteamID().."', 'guest')" query(SQLquery, ply) end function refresh() for k, v in pairs (player.GetAll()) do v:PrintMessage(HUD_PRINTCENTER,"Welcome to the server "..v:Nick().."! Your SteamID is "..v:SteamID()..".") SQLquery = "SELECT * FROM gmod_class WHERE steamid = '"..v:SteamID().."'" query(SQLquery, v) end end concommand.Add( "MySQLRefresh", refresh) [/lua]
To add, you're re-running query() which calls AddPlayer(), don't do that, query doesn't check if the player is in the database, it checks the table of the query you send is valid, which will return nothing for inserting.
Sorry, you need to Log In to post a reply to this thread.