I execute an SQL query using DarkRP's SQL (Which is the MySQLite.blahblah bit) functions and I need it to detect if the user has set a pin or not. If the user has not set a pin (meaning, the pin is equal to NULL) then show up a menu to set one.
I have the SQL query fetching the pin just fine and if its blank I can do print(data) and it just returns NULL like it should. Trouble is if I try to do the if statement with the data to detect if its NULL or not and it just returns that its not null in any case wether the variable is null or not.
[lua]
function ENT:Use(act)
MySQLite.queryValue("SELECT pin FROM chiz_test WHERE unique_id='".. act:UniqueID() .."'", function(data)
if data then
umsg.Start("loginPass", act)
umsg.End()
else
umsg.Start("setPass", act)
umsg.End()
end
end)
end
[/lua]
any ideas?
[QUOTE=Handsome Matt;43394501]Where did you find this ancient code, what is MySQLite, why is player nil, why are you using usermessages, why are you using usermessages wrong.[/QUOTE]
The old Garrys Mod wiki :v: . Derp, typo. Im using usermessages because its what im used to at the moment, dont worry, I shal educate my self on the net library soon enough. Am I using them wrong? I didnt realize.
[QUOTE=Chizbang;43394628]The [b]old[/b] Garrys Mod wiki.[/QUOTE]
[QUOTE=Robotboy655;43394779][/QUOTE]
The new one has rather a lot missing. The only thing I can see thats acient about the code I posed is the umsg bit but atleast that part works. From what I can make out its just a wrapper for the net library anyway, right?
Yeah but what im getting at is, the problem isnt caused by ancient code, right? (because the only thing thats ancient from what I can see, like you said before are the umsgs)
[lua]
local q = sql.Query( string.format( "SELECT pin FROM chiz_test WHERE unique_id = %i", act:UniqueID() ) )
if !q then
--do your stuff incase it's null
else
--yay its there, do your stuff
end
[/lua]
For those who don't know in this thread, MySQLite is DarkRP 2.5.0's database module that combines MySQL and SQLite support.
[editline]3rd January 2014[/editline]
[url]https://github.com/FPtje/DarkRP/blob/master/gamemode/libraries/database.lua[/url]
I fixed it for him through Steam. The query was working fine, the problem was that when he inserted the row, he didn't put anything in the pin value, so it inserted NULL into the database, which is why he was receiving NULL.
Yup! Thanks Coffeee!
Life saver.
Sorry, you need to Log In to post a reply to this thread.