MySql Help(Runned in lua)

hey in the PlayerInitialSpawn i tried to do, so it creates your information if it doesnt exists on a MySql database so here is my Function

[lua]
function GM:PlayerInitialSpawn(ply)

ply:SetTeam(TEAM_CITIZEN)

print("Connecting to MySql database")
local db, error = mysql.connect("127.0.0.1", "****", "****", "garrysmod_mysqlserver", "****")
if (db == 0) then print(tostring(error) .. "

") return end
print("Connected to MySql database
")

local PlayerData = mysql.query(db, "SELECT steamid FROM rp_players WHERE steamid = '"..ply:SteamID().."'") 
print("Player data loaded")

if (PlayerData) then
	print("Player data exists")
else
print("Player data does not exist")
	mysql.query(db, "INSERT INTO rp_players (steamid,money) VALUES('" .. ply:SteamID() .. "','" .. 500 .. "');");
end

end
[/lua]

for some reason it prints “Player data exists” in my server console, even though there is nothing in that table, could someone please tell me whats wrong

[editline]07:30PM[/editline]

i know its something with the local PlayerData cause when i change the if statement to !PlayerData it makes the information

Playerdata is a table so it should be tostring(PlayerData[1][1]) or something or tonumber. I dont know what i did.

ohh so when you do that kinda stuff, it makes a table, ohh i thought it made strings, thanks alot.

[editline]07:42PM[/editline]

Player data loaded
ERROR: GAMEMODE:‘PlayerInitialSpawn’ Failed: CityRP\gamemode\hooks.lua:42: attem
pt to index field ‘?’ (a nil value)

it doesnt says ? anywhere

i wrote this
if (PlayerData[1][1]) then
and tried
if (tostring(PlayerData[1][1])) then

[editline]07:45PM[/editline]

and btw line 42 is if (PlayerData[1][1]) then

[editline]07:52PM[/editline]

i tried with
if (PlayerData[1] and PlayerData[1][‘steamid’]) then
first it looked fine but when i rejoined i was made one more time.

[editline]08:00PM[/editline]

i used printtable and the table is empty for some reason
i have a picture of my database at
http://gorgorp.no-ip.org/database.jpg

[editline]08:16PM[/editline]

someone please help?

I give you my code, hope it helps
[lua]
function GM:PlayerSpawn(ply)
// Check if User exists in the Database

//Connect to MySQL
local db2, error = mysql.connect(ip,user,pass,data)
if (db2 == 0 ) then print (tostring(error)) return end
	
//Lookup the "Friends" Table
local suche2 = mysql.query(db2, "SELECT count(*) FROM friends WHERE steam = '"..ply:SteamID().."'");

//If user is in the "Friends" Table, then ... Beem me up Scotty to Team3

if (tonumber(suche2[1][1]) == 0) then
ply:SetTeam(2) if ply:IsAdmin() then ply:SetTeam (1) end
else
ply:SetTeam(3) if ply:IsAdmin() then ply:SetTeam (1) end
end
//Disconnect for Security and the "Too many Connections" Error. 
local succ2, error = mysql.disconnect(db)
//End	

self.BaseClass:PlayerSpawn( ply )   
ply:SetGravity( 0.75 ) 
ply:SetMaxHealth(150,true)
ply:SetWalkSpeed(300)
ply:SetRunSpeed(350)
if ply:IsAdmin() then
ply:SetWalkSpeed(AdminWSpeed)
ply:SetRunSpeed (AdminRSpeed)
end	

end
[/lua]

i figured it out now, with some help from Nick Tellis

[editline]09:08PM[/editline]

and thanks to you Peacemaker

Oh, okay

now i do like
[lua]
function GM:PlayerInitialSpawn(ply)

ply:SetTeam(TEAM_CITIZEN)

local db, error = mysql.connect("127.0.0.1", "****", "****", "garrysmod_mysqlserver", "****")
if (db == 0) then print(tostring(error) .. "

") return end

local PlayerData = mysql.query(db, "SELECT steamid FROM rp_players WHERE steamid = '"..ply:SteamID().."'") 
PlayerData = PlayerData or {};

if PlayerData and PlayerData[1] then
	print("Player data exists")
else
	print("Player data does not exist")
	mysql.query(db, "INSERT INTO rp_players (steamid,money) VALUES('" .. ply:SteamID() .. "','" .. 500 .. "');");
end

end
[/lua]

Ahhh use [lua] [/lua] for the love of god

what do you mean fish?

He wants you to use [lua] tags.

is that like
[lua]
hey
[lua]

[editline]09:35PM[/editline]

i guess no, how then?

[lua][/ lua] (without the space)

[lua]
print(“this works(i hope)”)
[/lua]

[editline]09:38PM[/editline]

nice thanks