Selecting in the SQLite database

-snip- Thanks dr.Tight!

-snip- edited that ^

[lua]
if( args[1] == “spyder” )then
local select = sql.Query( “SELECT ‘spyder’ FROM TS2Characters WHERE id = '” … ply:GetField( “charid” ) … “’” )
if ( !select ) then --This line
Console( ply, “You already have that car!”, true )
else
if ply:CanAfford( 1900 ) then
ply:TakeMoney( 1900 )
Console( ply, “Bought a 360Spyder for $1900! The car is now in your garage!”, true )
sql.Query( “UPDATE TS2Characters SET ‘spyder’ = ‘yes’ WHERE SteamID = '” … ply:SteamID() … “’ AND id = '” … ply:GetField( “charid” ) … “’;” );
end
end
end
[/lua]

Where I commented is where I think your problem is at. You are querying if spyder exists in the players data, and if it doesn’t to tell them that they already have it. Which is incorrect. Basically, you have it backwards.

[Lua]
local cartbl = {}
cartbl[“spyder”] = 1900
cartbl[“truckfront”] = 2400
cartbl[“bmw”] = 2300
cartbl[“lotus”] = 2600
cartbl[“markiv”] = 2100
cartbl[“murcielago”] = 3100

function buyfuckingcar( ply, cmd, args )
local car = string.lower(args[1])
local cost = cartbl[car]
local charid = ply:GetField(“charid”)
if cost then
local select = tonumber(sql.QueryValue(string.format(“SELECT %s FROM TS2Characters WHERE id = %d”,car,charid)))
if !select or select == 0 then
if ply:CanAfford( cost ) then
ply:TakeMoney( cost )
Console( ply, string.format(“Bought a %s for %d! The car is now in your garage!”,car,cost), true)
sql.Query( string.format(“UPDATE TS2Characters SET %s = 1 WHERE SteamID = %s AND id = %d”,car,sql.SQLStr(ply:SteamID()),ply:GetField(“charid”)))
end
else
Console(ply, “You already have that car!”, true)
end
else
Console(ply, string.format("%s is not a valid car",car), true)
end
end
concommand.Add( “buyfuckingcar”, buyfuckingcar )
[/Lua]