Wei Posted July 17, 2012 Posted July 17, 2012 executeSQLCreateTable ( "test", "username TEXT" ) function addInfoToSQL() local sourcename = getPlayerName ( source ) result = executeSQLSelect ( "test", "username", "username = '" .. getAccountName(getPlayerAccount(source)) .. "'" ) if ( result == false ) then outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source ) executeSQLInsert ( "players","'" .. getAccountName(getPlayerAccount(source)) .. "'" ) else outputChatBox ( "Welcome back " .. ??? .. "!", source ) -- what should I put here to get player username ? executeSQLUpdate ( "test", "username = '" .. sourcename .. "'" ) end end addEventHandler ( "onPlayerLogin", getRootElement(), addInfoToSQL) Look at line 10 Diet with russian vodka, lose 3 days in one week !
Vision Posted July 17, 2012 Posted July 17, 2012 executeSQLCreateTable ( "test", "username TEXT" ) function addInfoToSQL() local sourcename = getPlayerName ( source ) local acc = getAccountName ( getPlayerAccount ( source ) ) result = executeSQLSelect ( "test", "username", "username = '" .. getAccountName(getPlayerAccount(source)) .. "'" ) if ( result == false ) then outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source ) executeSQLInsert ( "players","'" .. getAccountName(getPlayerAccount(source)) .. "'" ) else outputChatBox ( "Welcome back " .. acc .. "!", source ) -- what should I put here to get player username ? executeSQLUpdate ( "test", "username = '" .. sourcename .. "'" ) end end addEventHandler ( "onPlayerLogin", getRootElement(), addInfoToSQL)
Wei Posted July 17, 2012 Author Posted July 17, 2012 *facepalm* I wan't it from SQL... Diet with russian vodka, lose 3 days in one week !
TwiX! Posted July 17, 2012 Posted July 17, 2012 *facepalm*I wan't it from SQL... you are *facepalm* his code is work - Working on [php/HTML/Mysql/Lua/Java Scripts/Web Design/3D Modeling]
Wei Posted July 17, 2012 Author Posted July 17, 2012 I want it that it will get it from SQL !! Not getAccountName... Diet with russian vodka, lose 3 days in one week !
InDev Posted July 17, 2012 Posted July 17, 2012 On this you can find: "Returns a 2-dimensional table where the results are stored as table [row_index] [column_name]" I think you can just put: outputChatBox ( "Welcome back " .. result[1]["username"] .. "!", source ) The first row_index in your result table is the first row who matches the SELECT request conditions in your SQL table, the column_name "username" contains what you need to retrieve, I think. I can be wrong, tell me if it works. Welcome to the beginning...
Wei Posted July 17, 2012 Author Posted July 17, 2012 ERROR: a\sDatabase.lua:12: attempt to index field '?' (a nil value) Diet with russian vodka, lose 3 days in one week !
InDev Posted July 17, 2012 Posted July 17, 2012 This seems to works, I've changed the test condition on result by the one provided in the wiki: executeSQLCreateTable ( "test", "username TEXT" ) function addInfoToSQL() local sourcename = getPlayerName ( source ) local result = executeSQLSelect ( "test", "username", "username = '" .. getAccountName(getPlayerAccount(source)) .. "'" ) if ( type( result ) == "table" and #result == 0 ) or not result then outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source ) executeSQLInsert ( "test","'" .. getAccountName(getPlayerAccount(source)) .. "'" ) else outputChatBox ( "Welcome back " .. result[1]["username"] .. "!", source ) -- what should I put here to get player username ? executeSQLUpdate ( "test", "username = '" .. sourcename .. "'" ) end end addEventHandler ( "onPlayerLogin", getRootElement(), addInfoToSQL) Welcome to the beginning...
Wei Posted July 17, 2012 Author Posted July 17, 2012 Thank You ! Diet with russian vodka, lose 3 days in one week !
InDev Posted July 17, 2012 Posted July 17, 2012 Thank You ! You're welcome Welcome to the beginning...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now