xXMADEXx Posted May 22, 2013 Posted May 22, 2013 Hi guys, im trying to get the "password" column, where the player's account is. Here is what i got, but i got stuck. function getAccountPassword ( player, command, account ) if ( account ) and ( type ( account ) == "string" ) then if ( doesAccountExist ( account ) == true ) then local new = dbQuery ( dbc, "SELECT * FROM Accounts WHERE name=?", accnt ) local result,n_rows = dbPoll ( new, - 1 ) -- Not to sure what to do... -- outputChatBox ( tostring ( n_rows ) ) end end end addCommandHandler ( "ga", getAccountPassword ) The Ultimate Lua Tutorial! | MTA PHP SDK
Castillo Posted May 22, 2013 Posted May 22, 2013 Use this to get the password column data: local password = result [ 1 ] [ "passwordColumnNameHere" ] San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
xXMADEXx Posted May 22, 2013 Author Posted May 22, 2013 I tried that, but now its saying "unknown index," so i made this code: -- Get accounts password -- function getAccountPassword ( player, command, account ) if ( account ) and ( type ( account ) == "string" ) then if ( doesAccountExist ( account ) == true ) then local new = dbQuery ( dbc, "SELECT * FROM Accounts WHERE name=?", accnt ) local result,n_rows = dbPoll ( new, - 1 ) -- Not to sure what to do... -- local password = result[2] outputChatBox ( tostring ( password ) ) end end end addCommandHandler ( "ga", getAccountPassword ) and its returning nil. The Ultimate Lua Tutorial! | MTA PHP SDK
Castillo Posted May 22, 2013 Posted May 22, 2013 I said result [ 1 ], not result [ 2 ], as it only found one row for sure. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
xXMADEXx Posted May 22, 2013 Author Posted May 22, 2013 (edited) I said result [ 1 ], not result [ 2 ], as it only found one row for sure. Still is returning nil... Here is the code: -- Get accounts password -- function getAccountPassword ( player, command, account ) if ( account ) and ( type ( account ) == "string" ) then if ( doesAccountExist ( account ) == true ) then local new = dbQuery ( dbc, "SELECT * FROM Accounts WHERE name=?", accnt ) local result = dbPoll ( new, - 1 ) -- Not to sure what to do... -- local password = result[1] outputChatBox ( tostring ( password ) ) end end end addCommandHandler ( "ga", getAccountPassword ) Edited May 22, 2013 by Guest The Ultimate Lua Tutorial! | MTA PHP SDK
Castillo Posted May 22, 2013 Posted May 22, 2013 Show me the new code. Edit: This is wrong: local password = result[1] you aren't defining which column name you whish to get the data from, use this: local password = result [ 1 ] [ "password" ] San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
xXMADEXx Posted May 22, 2013 Author Posted May 22, 2013 Error: attempted to index field '?' (a nil value) The Ultimate Lua Tutorial! | MTA PHP SDK
Castillo Posted May 22, 2013 Posted May 22, 2013 That's because the account doesn't exist, which is because you are using the wrong argument here: local new = dbQuery ( dbc, "SELECT * FROM Accounts WHERE name=?", accnt ) "accnt" is not the same as "account". San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
xXMADEXx Posted May 22, 2013 Author Posted May 22, 2013 wow how did i miss that? Code is working now Thank you. The Ultimate Lua Tutorial! | MTA PHP SDK
Castillo Posted May 22, 2013 Posted May 22, 2013 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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