Wei Posted July 17, 2012 Share 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 Link to comment
Vision Posted July 17, 2012 Share 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) Link to comment
Wei Posted July 17, 2012 Author Share Posted July 17, 2012 *facepalm* I wan't it from SQL... Link to comment
TwiX! Posted July 17, 2012 Share Posted July 17, 2012 *facepalm*I wan't it from SQL... you are *facepalm* his code is work Link to comment
Wei Posted July 17, 2012 Author Share Posted July 17, 2012 I want it that it will get it from SQL !! Not getAccountName... Link to comment
InDev Posted July 17, 2012 Share 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. Link to comment
Wei Posted July 17, 2012 Author Share Posted July 17, 2012 ERROR: a\sDatabase.lua:12: attempt to index field '?' (a nil value) Link to comment
InDev Posted July 17, 2012 Share 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) Link to comment
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