here is my code
require( "mysqloo" )
DB_HOST = "localhost"
DB_PORT = 3306
DB_NAME = "badminmod"
DB_USERNAME = "root"
DB_PASSWORD = ""
function connectToDatabase()
databaseObject = mysqloo.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_PORT)
databaseObject.onConnected = function() print("Connected to Database") end
databaseObject.onConnectionFailed = function() print("Database could not be found") end
end
connectToDatabase()
function checkQuery(query)
local playerInfo = query:getData()
if playerInfo[1] ~= nil then
return true
else
return false
end
end
function FirstJoinMysql( ply )
local query1 = databaseObject:query("SELECT * FROM bam_players WHERE ID = '" .. ply:SteamID() .. "'")
query1.onSuccess = function(q)
if not checkQuery(q) then
local query2 = databaseObject:query("INSERT INTO bam_players(ID, Name) VALUES ('" .. ply:SteamID() .. "'," .. ply:SteamName() .. ")")
query2.onSuccess = function(q) print("Your Info Was Stored") end
query2.onError = function(q,e) print("Your Info Was Not Stored") end
query2.start()
else
print("You are already created")
end
end
query1.OnError = function(q,e) print("Failed") end
query1.start()
end
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", FirstJoinMysql )
I get this error
[ERROR] addons/badminmod/lua/autorun/server/bam.lua:40: attempt to index local 'query1' <a nil value>
1. v - addons/badminmod/lua/autorun/server/bam.lua:40
2. unknown - lua/includes/modules/hook.lua:84
What Iam I doing wrong?