SQL query confused...

Hello, I have recently tried to use SQL within LUA and connected perfectly.
However I cannot seem to use the SQL queries to check to see if the entries exist or not. This is my current code.



local isunique = mysql.query(db,"SELECT (id) FROM members WHERE (steam) = ('"..steamID.."')");
if(isunique) then
	Msg("exists already")
else
	Msg("Doesn't Exist")
end


Try this, havn’t tested but it should work, I use a custom I made system for mysql so I am a little rusty on the default way. Post if it does not work.

[lua]
local isunique = mysql.query( db, “SELECT count(*) FROM members WHERE steam = '” … ply:SteamID() … “’” )
if( isunique[1][1] == 1 ) then
Msg( “exists already” )
else
Msg( “Doesn’t Exist” )
end
[/lua]

Doesn’t seem to accept it I can enter a matching steam id into my db and it still says doesn’t exist…
It’s rather frustrating bah! hehe

Post all your code please, and make sure you edit out your connection string details.



function NotifyOfSpawn(ply)
// use ply:Nick() in db
require( "mysql" )
// db connection info
local db, error = mysql.connect("x", "x", "x", "x")
if (db == 0) then print(tostring(error) .. "
") return end

steamID = ply:SteamID()
nickN = ply:Nick()
deaths = ply:Deaths()

local isunique = mysql.query( db, "SELECT count(*) FROM members WHERE steam = '" .. ply:SteamID() .. "'"  )
if( isunique[1][1] == 1 ) then
	Msg( "exists already" )
else
	Msg( "Doesn't Exist" )
end

local succ, error = mysql.disconnect(db)
if (not succ) then
	print( error );
end
print("connection closed!
");

end

hook.Add( "PlayerSpawn", "PlayerSpawnMessages", NotifyOfSpawn )


Here this works, not sure but it was returning it as a string, when pretty much my same code returns it as a number.

[lua]
local isunique = mysql.query( db, “SELECT count(*) FROM users WHERE SteamID = '” … ply:SteamID() … “’” )
if isunique[1][1] == “1” then
Msg( “exists already” )
elseif isunique[1][1] == “0” then
Msg( “Doesn’t Exist” )
end
[/lua]

thanks for the help dude, worked would never have worked that out haha!

By the way, you should require stuff at the top of your code outside of any functions or stuff generally.