I am trying to code in a mysql feature to log the users on my server, and it does not want to work past a certian point.
This is in my init.lua:
[lua]function sqlCheck(ply)
local steam = ply:SteamID()
ply:PrintMessage(HUD_PRINTTALK, steam);
local db, error = mysql.connect("82.103.138.122", "user", "pass", "dbname", "port");
if (db == 0) then
ply:PrintMessage(HUD_PRINTTALK, error);
end
local tab, succ, error = mysql.query(db, Format("SELECT * FROM rave1 WHERE steam = '%s'", steam));
if (not succ) then
ply:PrintMessage(HUD_PRINTTALK, error);
end
if (tab) then
ply:PrintMessage(HUD_PRINTTALK, "Yes");
else
ply:PrintMessage(HUD_PRINTTALK, "No.");
end
local succ, error = mysql.disconnect(db);
if (not succ) then
ply:PrintMessage(HUD_PRINTTALK, error);
end
return
end
concommand.Add("checkme",sqlCheck)[/lua]
Yes, I have require("mysql") in my code. The issue is it will not print anything other than the players steam id. Any ideas?
Do you have the dlls in the right places? libMySQL in the srcds.exe folder?
[QUOTE=Skapocalypse;18481450]Do you have the dlls in the right places? libMySQL in the srcds.exe folder?[/QUOTE]
I host my server with Xenon Servers and they have an automated installer for it. As far as I can tell, yeah (cant see srcds.exe folder)
and an else to the if (db == 0) check. And have it print if it connects first. Then go from there. Make sure the table names are correct etc.
[QUOTE=Skapocalypse;18481636]and an else to the if (db == 0) check. And have it print if it connects first. Then go from there. Make sure the table names are correct etc.[/QUOTE]
Changed it to:
[lua]if (db == 0) then
ply:PrintMessage(HUD_PRINTTALK, error);
else
ply:PrintMessage(HUD_PRINTTALK, "Connected to db.");
end
local tab, succ, error = mysql.query(db, Format("SELECT * FROM rave1 WHERE steam = %s", steam));
if (not succ) then
ply:PrintMessage(HUD_PRINTTALK, error);
end
if (tab) then
ply:PrintMessage(HUD_PRINTTALK, "Yes.");
else
ply:PrintMessage(HUD_PRINTTALK, "No.");
end
local succ, error = mysql.disconnect(db);
if (not succ) then
ply:PrintMessage(HUD_PRINTTALK, error);
end
return[/lua]
And got:
] checkme
STEAM_0:1:10933873
Connected to db.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':1:10933873' at line 1
Yes.
[editline]09:14PM[/editline]
I forgot to add:
The only thing in rave1 (name, steam, ip, last_used, uid) is this:
VALUES('Lynx', 'STEAM_0:0:26397314', '', '', 1)
[editline]09:18PM[/editline]
It is connecting and retrieving the information fine, the issue is the script cannot tell whether or not the steam id is in the database. How is the tab (result from mysql.Query) handled and how would I check if a value is in it?
From my code:
[lua]
function GM:PlayerInitialSpawn(Ply)
local CHECK = POAM.DBINFO( Ply )
if CHECK[1] and CHECK[1][2] then
--Player Exists
else
-- Player Does Not exist. Insert player's info into database.
end
end
function POAM.DBINFO( ply )
return mysql.query( DB, "SELECT * FROM PlayerINFO WHERE steamid = '" .. POAM.FormatSteam(ply) .. "'" )
end
[/lua]
[editline]07:18AM[/editline]
FormatSteam is just a function I use. You can just do ply:SteamID().
If you did tab['steamid'], it would return the steamid you just put into it. That's how you access the ->table<- from the mysql database.
The final query is probably being written as
SELECT * FROM rave1 WHERE steam = STEAM_0:1:10933873
when it should be
SELECT * FROM rave1 WHERE steam = 'STEAM_0:1:10933873'
or
SELECT * FROM rave1 WHERE steam = "STEAM_0:1:10933873"
Try this
[lua]
local tab, succ, error = mysql.query(db, 'SELECT * FROM rave1 WHERE steam = '..SQLStr(steam));
[/lua]
Sorry, you need to Log In to post a reply to this thread.