Jump to content

[HELP] database problem


BenceDev

Recommended Posts

Hi everyone!

I have a problem, so my problem is i want to get a number from table (example: i save player skin id to database when he register it [it works for me], and after he logged in set player skin to his saved id), but i dont know how to do it.

This is from my server sided script when he log in:
 

addEvent("loginRequest", true)
function loginRequest(player, username, password)
    local check = exports.fs_sql:_QuerySingle("select * from users where username = ? ", username)
    if check then
        local checkPass = check.password
        if (checkPass == password) then
            logIn(player, getAccount(username), tostring(password))
            triggerClientEvent(player, "showHide", getRootElement())
            local skinID = exports.fs_sql:_QuerySingle("select * from users where pSkin = ?", SkinTable)
            local toNumberExsSkin = tonumber(skinID)
            setElementModel(source, skinID)
            outputChatBox ( "#34bf49Successful login!", source, 255, 255, 255, true )
            fadeCamera(source, true)
            setCameraTarget(source,source)
        else
            outputChatBox ( "#ff4c4cWrong password!", source, 255, 255, 255, true )
        end
    end
end
addEventHandler("loginRequest", getRootElement(), loginRequest)


and this is my debugscript 3 says:

WARNING: [Core]\fs_loginSystemGui\server.lua:39: Bad argument @ 'setElementModel' [Expected number at argument 2, got nil]

and this is my database:
spacer.png

and in red square i want this number for skin id

Thanks for all help! :)

spacer.png spacer.png

Link to comment
34 minutes ago, AaroN⍩ said:

Test

SELECT pSkin FROM users WHERE username = ?

It would stay that way, I think:

 

   local skinID = exports.fs_sql:_QuerySingle("SELECT pSkin FROM users WHERE username = ?", username)

this is not working

debugscript says:
warning: bad argument @ 'setElementModel' [Expected number at argument 2, got table]

Link to comment
            local skinID = exports.fs_sql:_QuerySingle("select * from users where pSkin = ? and username = ?", SkinTable, username)

or 

            local skinID = exports.fs_sql:_QuerySingle("select * from users where username = ? and pSkin = ?", username, SkinTable)

or more simple 

    local check = exports.fs_sql:_QuerySingle("select * from users where username = ? ", username)
    if check then
        local checkPass = check.password
        if (checkPass == password) then
    
           local pSkin = check.pSkin
    ...
    
    

simple

 

 

Edited by alex17"
  • Like 1
Link to comment
12 hours ago, alex17" said:
            local skinID = exports.fs_sql:_QuerySingle("select * from users where pSkin = ? and username = ?", SkinTable, username)

or 

            local skinID = exports.fs_sql:_QuerySingle("select * from users where username = ? and pSkin = ?", username, SkinTable)

or more simple 

    local check = exports.fs_sql:_QuerySingle("select * from users where username = ? ", username)
    if check then
        local checkPass = check.password
        if (checkPass == password) then
    
           local pSkin = check.pSkin
    ...
    
    

simple

 

 

thanks and i test it now

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