xXMADEXx Posted May 22, 2013 Share 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 ) Link to comment
Castillo Posted May 22, 2013 Share Posted May 22, 2013 Use this to get the password column data: local password = result [ 1 ] [ "passwordColumnNameHere" ] Link to comment
xXMADEXx Posted May 22, 2013 Author Share 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. Link to comment
Castillo Posted May 22, 2013 Share Posted May 22, 2013 I said result [ 1 ], not result [ 2 ], as it only found one row for sure. Link to comment
xXMADEXx Posted May 22, 2013 Author Share 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 Link to comment
Castillo Posted May 22, 2013 Share 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" ] Link to comment
xXMADEXx Posted May 22, 2013 Author Share Posted May 22, 2013 Error: attempted to index field '?' (a nil value) Link to comment
Castillo Posted May 22, 2013 Share 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". Link to comment
xXMADEXx Posted May 22, 2013 Author Share Posted May 22, 2013 wow how did i miss that? Code is working now Thank you. 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