View Full Version : help with sql
CookieM
05-17-2009, 04:11 PM
Hi, i'm just playing around with SQL and to check it worked i tried this:
local Query = SQL.query("SELECT * FROM users")
outputChatBox(PlayerID,Query,255,0,0,255)
when i use the command to execute that it just shows SELECT * FROM users in the chatbox. what am i doing wrong? cheers
I think you need to use 'getReturnedLineData()' to fetch the query result. like so
SQL.query("SELECT * FROM users")
local b = SQL.getNumberOfReturnedLines()
for a=1, b do
local Line = getReturnedLineData(a)
outputChatBox(PlayerID,Line,255,0,0,255)
end
CookieM
05-17-2009, 05:22 PM
ah.. cheers mex
edit: i tried that, but in game it just says "NULLED".
edit2: ok i've sorted it now. but now i can't get it to insert data.
function Register(PlayerID,Password)
SQLConnect()
local PlayerName = getPlayerName(PlayerID)
SQL.query("INSERT INTO users (username, password) VALUES (PlayerName, Password)")
outputChatBox(PlayerID,"Congrats " .. PlayerName .. " you have successfully registered!",255,0,0,255)
end
addCommand("register","Register")
the console just says...
[SQL] Attempting to connect to the MySQL server [localhost@vco]...
[SQL] The connection to the MySQL server has succeeded.
[SQL] The MySQL query has encountered an error. [Unknown column 'PlayerName' in 'field list']
tuntis
05-17-2009, 10:56 PM
You forgot the semicolons in "VALUES (PlayerName, Password)" (which is why you get a SQL syntax error). You want to do something like:
VALUES (' " .. PlayerName .. " ', ' " .. Password .. " ')