Jump to content

MySQL - getting column data


Recommended Posts

Posted

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 ) 

Posted

Use this to get the password column data:

local password = result [ 1 ] [ "passwordColumnNameHere" ] 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

Posted

I said result [ 1 ], not result [ 2 ], as it only found one row for sure.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (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 by Guest
Posted

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.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...