SQL Update query refuses to work without an error

I have a query in my code that should update the data in the database. SELECT and INSERT queries are working but UPDATE is not.

My table looks like this: “CREATE TABLE player_info ( unique_id text, money text)”

This is the code:



money = sql.QueryValue("SELECT money FROM player_info WHERE unique_id = '"..steamID.."'")
amount = money+amount
query = "UPDATE player_info SET money='"..amount.."' WHERE unique_id='"..SteamID.."'"
result = sql.Query(query)
if result then
	print "hmmmmmmm"
else
	print (sql.LastError())
	print (query)
end


When I print the query it returns: http://puu.sh/1BZjD

Thanks in advance!

Post the entire code block, including the portion where you created the table. I’m guessing that you don’t have any values in your table so when you call your query it returns nil because you’re looking for a value in a field that has no entries

Obviosly if it returns the amount of money from the database then there is data to get from…

So does that mean you’re not going to post the code or what? You only addressed the latter half of what I posted.

SET money = ‘5050’ is probably why. You don’t use quotes on non-strings.

still doesnt work…

Your UPDATE query has a nil variable being concatenated in it (you used “SteamID” as opposed to your “steamID” variable that was used in the SELECT query)
Though Lua should throw an error for that…

Edit:
Nevermind, screenshot shows it working
Just check the variable is correctly named in the actual code. Or just post your current code, because that can’t be your real code (steamID != SteamID in Lua) unless you have two variables, one called SteamID and one steamID which would be silly



function AddMoney(ply, amount)
	if not amount then return false end
	SteamID = ply:GetNWString ("SteamID")
	money = sql.QueryValue("SELECT money FROM player_info WHERE unique_id = '"..SteamID.."'")
	amount = money+amount
	query = "UPDATE player_info SET money='"..amount.."' WHERE unique_id='"..SteamID.."'"
	result = sql.Query(query)
	if result then
		print "hmmmmmmm"
	else
		print (query)
	end
end


Try changing SteamID = ply:GetNWString (“SteamID”)
To SteamID = ply:SteamID()?

[editline]17th December 2012[/editline]

Also, just check it isn’t actually working by viewing the SQL table with an SQLite browser
I wouldn’t expect an UPDATE query to return anything other than nil, and if I recall correctly nil has the same effect as false if used in an “if” statement. THen again these last 2 statements could be wrong

This is the structure: http://puu.sh/1C6M6
The data: http://puu.sh/1C6MO

If I run the query from the database browser then it works as it should…

From your OP:
http://puu.sh/1C6MO

It appears to have worked correctly (5055 with that SteamID in the screenshot). Unless you have changed the amount that SteamID has, then tested to see if it changes and found that it does not update correctly?
But yeah, the code looks ok as far as I can tell, unless I’m missing something

The 5055 i changed from the browser. The problem is that code is okay and it outputs the query but with but in the browser the query works…

Edit:
This all is for my new gamemode that will be RP based.
A sneak peak on how the HUD looks: http://cloud.steampowered.com/ugc/903234677572554619/A5FF92BFDB538170DA5062D285EADC724B4DBEE5/

Help please?

[editline]18th December 2012[/editline]

Okay I tried it this way but it doesnt work either:

fquery = "DELETE FROM player_info WHERE unique_id='"..SteamID.."'"
squery = "INSERT INTO player_info (`unique_id`, `money`) VALUES ('"..SteamID.."', '"..amount.."')"

fresult = sql.Query(fquery)
sresult = sql.Query(squery)

It helps to be more specific about exactly how it doesn’t work.

You’re not using SQLLite formatting.