The Error
[code]
mysql_functions.lua:19] attempt to index field '?' (a nil value)
[/code]
The Query
[lua]
function OwnChar(name, steamid)
local query = "SELECT steamid FROM characters WHERE name= '"..name.."'"
local owner = RunSingleQuery(query)
if owner == steamid then
return true
else
return false
end
end
[/lua]
The Function
[lua]
function RunSingleQuery(query)
if not query then return false end
local conn = mysql.connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATA)
local runquery = mysql.query(conn, query)
mysql.disconnect(conn)
return runquery[1][1] -- Where the error occurs
end
[/lua]
Try returning "runquery" or "runquery[1]" instead, it's trying to find a table value on a variable that doesn't exist.
How can I edit this to make it so that it returns false instead?
When I try it just errors out.
[B]return[/B] runquery[1][1] or false.
[QUOTE=Freze;26826615][B]return[/B] runquery[1][1] or false.[/QUOTE]
That would still cause an error if runquery or runquery[1] were nil.
[lua]if runquery and runquery[1] then return runquery[1][1] end[/lua]
[QUOTE=raBBish;26826793]That would still cause an error if runquery or runquery[1] were nil.
[lua]if runquery and runquery[1] then return runquery[1][1] end[/lua][/QUOTE]
[lua]return (runquery && runquery[1]) && runquery[1][1] || false[/lua]
:fuckyou:
Sorry, you need to Log In to post a reply to this thread.