What am I doing wrong??[Lua, SQL]

Ok now I have my code all situated and things but for some reason the code doesn’t seem to want to work. If someone can tell me at least what is wrong it would really be appreciated. Oh and I’m not too familiar with MySQL. Here is what I have so far:
[lua]AddCSLuaFile("_MYSQL.lua")
include("_MYSQL.lua")

function Initialiize()
player_donated()
end

function player_donated ( ply )
(
steamID = sql.Query(“SELECT steam FROM darkrp_wallets”)

result = sql.Query("SELECT status FROM darkrp_wallets WHERE status = 'admin'")
result2 = sql.Query("SELECT status FROM darkrp_wallets WHERE status = 'donator'")
result3 = sql.Query("SELECT status FROM darkrp_wallets WHERE status = 'NULL'")
if (result) then
		RunConsoleCommand("ulx adduserid " ..steamID.. " admin ")			// Call command to make person admin

elseif (result2) then                                // If the value isnt admin then make them supporter
		RunConsoleCommand("ulx adduserid " ..steamID.. " supporter ")
end)

end

function Check( ply )
if ply:IsAdmin() then
print(“You Are Already Admin!”)
return end
end

hook.Add( “PlayerInitialSpawn”, “PlayerInitialSpawn”, PlayerInitialSpawn )
hook.Add( “Checkforsql”, “Check”, Check )
hook.Add( “Initialize”, “Initialize”, Initialize)
[/lua]
Please help!

[editline]21st June 2012[/editline]

ill pay $5-$10 for whoever can do it :stuck_out_tongue:

You need " ; " at the end of your queries first of all, second that’s not how the SQL functions work in Gmod. Thirdly, You fucked up your hooks beyond belief. Fourth, Your Player_donated function is in the wrong area.



AddCSLuaFile("_MYSQL.lua")
include("_MYSQL.lua")
 
// You are more than likely doing this wrong.
// Put "player_donated(ply)" in GM:InitialPlayerSpawn() and it will probably work.
function Initialiize(ply)
        player_donated(ply)
end
 
function player_donated ( ply )
 
	local steamID = ply:SID() -- I think this is DarkRP's version
	
    sql.Query("SELECT status FROM darkrp_wallets WHERE steamID = " .. sql.SQLStr(steamID) .. ";",
	function(data)
		if not data then return end
		RunConsoleCommand("ulx adduserid " ..steamID.. " .. " " .. data[1])           // Call command to make person admin
	end)
   
end
 
function Check( ply )
    if ply:IsAdmin() then
		print("You Are Already Admin!")
		return
	end
end
 
 // What the fuck is all this stuff down here?
 // Your Initialize hook looks broken.
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
hook.Add( "Checkforsql", "Check", Check )
hook.Add( "Initialize", "Initialize", Initialize)


Actually, you don’t need semicolons after SQL queries, at least not when parsing them from gmod. I never used those and it always worked fine, both SQLite and MySQL

Firstly, what you are using there isn’t MySQL, it is SQLite, because that’s what GMod provides by default.

[lua]steamID = sql.Query(“SELECT steam FROM darkrp_wallets”)[/lua]

It isn’t clear what you are trying to do here, but either way, sql.Query returns a table containing all rows (which are also tables) that match your conditions. GMod provides a couple of useful functions to counter this - sql.QueryRow (takes the query and returns the first row found) and sql.QueryValue (returns the first(?) value found).

Either way, “SELECT steam FROM darkrp_wallets” would return ALL Steam ID’s in the table.
Also, this
[lua] result = sql.Query(“SELECT status FROM darkrp_wallets WHERE status = ‘admin’”)
result2 = sql.Query(“SELECT status FROM darkrp_wallets WHERE status = ‘donator’”)
result3 = sql.Query(“SELECT status FROM darkrp_wallets WHERE status = ‘NULL’”)[/lua]

Won’t work because you are selecting the value that you are searching by. What’s the point? Each of those will always return a table containing “admin”, “donator” or “NULL”, I guess that’s not what you were trying to do.

An easier way to do the above would be something like this. Don’t expect it to work like you want, although, since I may be misunderstanding you.

[lua]function player_donated ( ply )

local steamID = ply:SteamID()
 
local result = sql.QueryValue("SELECT status FROM darkrp_wallets WHERE steamID = " .. sql.SQLStr(steamID)) -- Note, that this may also be written as sql.Query("SELECT status FROM darkrp_wallets WHERE steamID = " .. sql.SQLStr(steamID))[1][1] , as in getting the first value of the first row returned.

if (result == "admin") then
    RunConsoleCommand("ulx", "adduserid", steamID, "admin")
elseif (result == "donator") then
    RunConsoleCommand("ulx", "adduserid", steamID, "supporter")
end

end[/lua]

Also, you don’t need a bracket after ‘end’, which is in your code. And RunConsoleCommand doesn’t work the way you used it, it takes each argument separately, like above.

@SeveredSkull, apparently default GMod SQL library doesn’t support callbacks, AFAIK, isntead it simply returns the value.

Alright but will this automatically run when the server starts?

anyone?? -bump-

Nevermind someone already got it for me:P

Sorry, been busy.

Sorry. Habit with mysqloo.