• MySQL query loop will not update int
    0 replies, posted
Hello everyone, This lua code is meant to add the player's steam ID and add 25 points to it every hour. However, the SQL query that adds 25 to the point column will not actually add 25 after adding it once. See the code here: [CODE]function playerFirstJoin(player) require ("mysqloo") // Include the modules local DATABASE_HOST = "--" // database host (can be an ip) local DATABASE_PORT = 3306 // port to the database, you probably wont need to change this unless you get told to local DATABASE_NAME = "--" // name of the database local DATABASE_USERNAME = "--" // username which you use to access it local DATABASE_PASSWORD = "--" // password of the username function connectToDatabase() databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT) databaseObject.onConnected = function() print("Database linked!") end databaseObject.onConnectionFailed = function() print("Failed to connect to the database.") end databaseObject:connect() end connectToDatabase() function checkQuery(query) local playerInfo = query:getData() if playerInfo[1] ~= nil then return true else return false end end PrintMessage( HUD_PRINTTALK, "Timer created" ) timer.Create("timer"..player:SteamID(), 10, 999999, addPoints, player); // repeats every 10 seconds for quicker debugging end hook.Add("PlayerInitialSpawn", "playerFirstJoin", playerFirstJoin); function addPoints(player) PrintMessage( HUD_PRINTTALK, "Adding 25 Points.." ) local query1 = databaseObject:query("SELECT * FROM Players WHERE ID = '" .. player:SteamID() .. "'") query1.onSuccess = function(q) if not checkQuery(q) then local query2 = databaseObject:query("INSERT INTO Players(ID) VALUE ('" .. player:SteamID() .. "')")// else create the bugger local query3 = databaseObject:query("UPDATE Players SET `Money` = `Money`+25 WHERE `ID` = '".. player:SteamID().."'") query2.onSuccess = function(q) PrintMessage( HUD_PRINTTALK, "Created you!") end query2.onError = function(q,e) PrintMessage( HUD_PRINTTALK, "something went wrong") end query2:start() query3.onSuccess = function(q) PrintMessage( HUD_PRINTTALK, "Updated with 25 Points!") end query3.onError = function(q,e) PrintMessage( HUD_PRINTTALK, "something went wrong") end query3:start() else print("You are already created!") end end query1.onError = function(q,e) PrintMessage( HUD_PRINTTALK, "something went wrong when checking") end query1:start() end function playerDisconnect() timer.Destroy("timer"..player:SteamID()); end hook.Add("PlayerDisconnected", "playerDisconnect", playerDisconnect);[/CODE] Even though it loops, the value for 'money' is still at 25. And in the chat, it does echo "adding Points..", but it does not successfully add them. Thanks, Gus
Sorry, you need to Log In to post a reply to this thread.