tmysql not updating/acting improperly.

Okay, so I have had trouble getting this to work for some reason… it looks like proper syntax but still for some reason i can’t seem to get it right.

first the code:

function Test.InsertCharIntoAccount(ply, cid)
	-- Gotta check to see how many characters there are already.
		 tmysql.query( "SELECT numchars FROM test_accounts WHERE steamid='"..tostring(ply:SteamID()).."'", 
		 function(res, status, error)
			PrintTable(res)
			if (tonumber(res[1]["numchars"]) == 0) then
				Msg("Were gonna go with this one")
				tmysql.query( "UPDATE `test_accounts` SET `cid1`='"..cid.. "' WHERE `steamid`='"..tostring(ply:SteamID()).."'",function(res) end, 1);
				tmysql.query("UPDATE `test_accounts` SET `numchars`=1 WHERE `steamid`="..tostring(ply:SteamID()).."'",function(res) end, 1);
				return true
			elseif(tonumber(res[1]["numchars"]) == 1) then
				tmysql.query( "UPDATE `test_accounts` SET `cid2`='"..cid.. "' WHERE `steamid`='"..tostring(ply:SteamID()).."'", function(res) end, 1);
				tmysql.query("UPDATE `test_accounts` SET `numchars`='2' WHERE `steamid`="..tostring(ply:SteamID()).."'",function(res) end, 1);
				return true
			elseif(tonumber(res[1]["numchars"]) == 2) then
				tmysql.query( "UPDATE `test_accounts` SET `cid3`='"..cid .. "' WHERE `steamid`='"..tostring(ply:SteamID()).."'", function(res) end, 1);
				tmysql.query("UPDATE `test_accounts` SET `numchars`='3' WHERE `steamid`="..tostring(ply:SteamID()).."'",function(res) end, 1);
				return true
			else
				test.Notify(ply, "I have no clue how you got this far, but you can't create a fourth character")
				PrintTable(res)
				return false
			end
		 
		end, 1)
end

I finally got it to where it actually goes into the conditionals… it used to just bypass right to the , “I have no clue how you got this far…” part. (I have no clue how I really did that but apparently I fixed it.)

The problem now is that it never updates numchars to = 1… I tried with ''s but that didn’t seem help any… whats wrong with my syntax??

Additional notes: The print tables were for debugging purposes. and the Msg("Were gonna go with this one too.)

How do I get this to update numchars >.<

Here’s how I would do it:

[lua]
local plymeta = _R.Player

function plymeta:HandleCharacterFailure(error)
test.Notify(self, “Unable to query your character”)
print("Backend error: ", error)
end

function plymeta:HandleCharacterUpdateFailure(result, status, error)
if status == 1 then return end

test.Notify(self, "Unable to save your character")
print("Backend error: ", error)

end

function plymeta:HandleCharacterCount(result, status, error)
if status == 0 || #result == 0 then
self:HandleCharacterFailure(error)
return
end

local numchars = tonumber(res[1]["numchars"])
local newindex = numchars + 1

if newindex &gt; 3 then
	self:FallbackHandleCharacterSlotsFull()
	return
end

local query = "UPDATE `test_accounts` SET `numchars` = " .. tostring(newindex) .. ", `cid" .. tostring(newindex) .. "` = '" .. tmysql.escape(self.PendingCID) .. "' WHERE `steamid` = '" .. tmysql.escape(self:SteamID()) .. "'"

tmysql.query( query, ply.HandleCharacterUpdateFailure, 0, ply)

end

function Test.InsertCharIntoAccount(ply, cid)
ply.PendingCID = cid

tmysql.query( "SELECT numchars FROM test_accounts WHERE steamid='" .. tmysql.escape(ply:SteamID()) .. "'", ply.HandleCharacterCount, 1, ply)

end
[/lua]

You don’t have to make everything inline functions, that’s why I added the callback arg.