Jump to content

SQL Problem


mjau

Recommended Posts

ok i got a problem when trying to get a vlue from db, and show it in label.

SQL function

function getBankMoney(acccountName) 
    local money = executeSQLSelect("players", "bankMoney", "accName = '"..accountName.."'") 
    return money[1]['bankMoney'] 
end 

Clientside functions in the script calling export

function updateMoney(balance) 
guiSetText (GUIEditor.label[1], "Current Balance: "..balance) 
end 
addEvent("updateMoney", true) 
addEventHandler("updateMoney", localPlayer, updateMoney) 
  
function getMoney() 
triggerServerEvent ( "getMoney", getLocalPlayer())  
end 

serverside function in the script calling the export

function getMoney() 
    local account = getPlayerAccount(source) 
    local accountName = getAccountName(account) 
    money = exports["SQL"]:getBankMoney(accountName) 
    triggerClientEvent ("updateMoney", source, money) 
end 
addEvent("getMoney", true) 
addEventHandler("getMoney", getRootElement(), getMoney) 

and now the error:

[2013-01-19 22:44:32] ERROR: [RLR]\SQL\main_S.lua:33: attempt to concatenate global 'accountName' (a nil value)

[2013-01-19 22:44:32] ERROR: call: failed to call 'SQL:getBankMoney' [string "?"]

Link to comment

Try this and see what it outputs:

function getBankMoney ( acccountName ) 
    if ( accountName ) then 
        local money = executeSQLSelect ( "players", "bankMoney", "accName = '".. accountName .."'" ) 
        return money [ 1 ] [ 'bankMoney' ] 
    else 
        outputChatBox ( "No account name" ) 
    end 
end 

Link to comment

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...