Jump to content

Problem in saving profile data in SQL


drk

Recommended Posts

Posted

I'm trying to save profile data ( player type the data in the memos and I want to save it in the SQL by the account name ) but when I restart the resource the data don't appear in the memo :S

The code:

Client:

addEventHandler('onClientGUIClick',root, 
    function() 
        if source == profile['save_label'] then 
            triggerServerEvent('onClickSave',localPlayer,getPlayerName(localPlayer),guiGetText(profile['name_memo']),guiGetText(profile['birthday_m']),guiGetText(profile['birthday_d']),guiGetText(profile['birthday_y']),guiGetText(profile['mail_memo'])) 
            triggerServerEvent('onSaveSettings',localPlayer) 
        end 
    end 
) 
  
addEventHandler('onLoginLoad',root, 
    function(name,month,day,year,mail) 
        guiSetText(profile['name_memo'],name) 
        guiSetText(profile['birthday_m'],month) 
        guiSetText(profile['birthday_d'],day) 
        guiSetText(profile['birthday_y'],year) 
        guiSetText(profile['mail_memo'],mail) 
    end 
) 
  

Server:

local table = executeSQLQuery("CREATE TABLE IF NOT EXISTS Profile ( player TEXT, name TEXT, month NUMBER, day NUMBER, year NUMBER, mail TEXT )") 
  
addEvent('onSaveOutput',true) 
addEvent('onClickSave',true) 
  
addEventHandler('onSaveOutput',root, 
    function() 
        outputChatBox('#ABCDEF* #ffffffYour settings have been saved!',source,255,255,255,true) 
    end 
) 
  
addEventHandler('onPlayerLogin',root, 
    function() 
        local select = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(getPlayerAccount(source)).."'") 
            if not result or #result == 0 then 
                local result = executeSQLQuery("INSERT INTO Profile VALUES ( '"..getAccountName(getPlayerAccount(source)).."', '', 'Month', 'Day', 'Year', '' )") 
            else 
                local resultt = executeSQLQuery("SELECT * FROM Profile WHERE player = "..getAccountName(getPlayerAccount(source)).."'") 
                triggerClientEvent('onLoginLoad',source,tostring(resultt[1]['name']),tostring(resultt[1]['month']),tostring(resultt[1]['day']),tostring(resultt[1]['year']),tostring(resultt[1]['mail'])) 
        end 
    end 
) 
  
addEventHandler('onClickSave',root, 
    function(thePlayer,name,month,day,year,mail) 
        local update = executeSQLQuery("UPDATE Profile SET name='"..name.."', month='"..month.."', day='"..day.."', year='"..year.."', mail='"..mail.."' WHERE player='"..getAccountName(getPlayerAccount(source)).."'") 
        triggerEvent('onSaveOutput',source) 
    end 
) 
  

I get no errors.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted
local table = executeSQLQuery("CREATE TABLE IF NOT EXISTS Profile ( player TEXT, name TEXT, month NUMBER, day NUMBER, year NUMBER, mail TEXT )") 
  
addEvent('onSaveOutput',true) 
addEvent('onClickSave',true) 
  
addEventHandler('onSaveOutput',root, 
    function() 
        outputChatBox('#ABCDEF* #ffffffYour settings have been saved!',source,255,255,255,true) 
    end 
) 
  
addEventHandler('onPlayerLogin',root, 
    function (_, account) 
        local result = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(account).."'") 
        if (not result or #result == 0) then 
            executeSQLQuery("INSERT INTO Profile VALUES ( '"..getAccountName(account).."', '', 'Month', 'Day', 'Year', '' )") 
        end 
        local resultt = executeSQLQuery("SELECT * FROM Profile WHERE player = "..getAccountName(account).."'") 
        triggerClientEvent('onLoginLoad',source,tostring(resultt[1]['name']),tostring(resultt[1]['month']),tostring(resultt[1]['day']),tostring(resultt[1]['year']),tostring(resultt[1]['mail'])) 
    end 
) 
  
addEventHandler('onClickSave',root, 
    function(thePlayer,name,month,day,year,mail) 
        local update = executeSQLQuery("UPDATE Profile SET name='"..name.."', month='"..month.."', day='"..day.."', year='"..year.."', mail='"..mail.."' WHERE player='"..getAccountName(getPlayerAccount(source)).."'") 
        triggerEvent('onSaveOutput',source) 
    end 
) 

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

Post or PM me the full client side, I'll test it on my server.

Edit: I've found the error:

--[[ 
    --@@author Draken 
    --@@18-02-2012 
]]-- 
  
local table = executeSQLQuery("CREATE TABLE IF NOT EXISTS Profile ( player TEXT, name TEXT, month NUMBER, day NUMBER, year NUMBER, mail TEXT )") 
  
addEvent('onPlayerNotLoggedIn',true) 
addEvent('isPlayerGuest',true) 
addEvent('onSaveSettings',true) 
addEvent('onSaveOutput',true) 
addEvent('onClickSave',true) 
  
addEventHandler('isPlayerGuest',root, 
 function() 
    local account = getPlayerAccount(source) 
        if not isGuestAccount(account) then 
            triggerClientEvent('onPanelOpen',source) 
        else 
            triggerEvent('onPlayerNotLoggedIn',source) 
    end 
end) 
  
addEventHandler('onPlayerNotLoggedIn',root, 
    function() 
        outputChatBox("#ABCDEF* #ffffffYou are not logged in!",source,255,255,255,true) 
    end 
) 
  
addEventHandler('onSaveOutput',root, 
    function() 
        outputChatBox('#ABCDEF* #ffffffYour settings have been saved!',source,255,255,255,true) 
    end 
) 
  
addEventHandler('onPlayerLogin',root, 
    function (_, account) 
        local result = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(account).."'") 
        if (not result or #result == 0) then 
            executeSQLQuery("INSERT INTO Profile VALUES ( '"..getAccountName(account).."', '', 'Month', 'Day', 'Year', '' )") 
        end 
        local resultt = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(account).."'") -- "'" was missing. 
        triggerClientEvent('onLoginLoad',source,tostring(resultt[1]['name']),tostring(resultt[1]['month']),tostring(resultt[1]['day']),tostring(resultt[1]['year']),tostring(resultt[1]['mail'])) 
    end 
) 
  
addEventHandler('onClickSave',root, 
    function(thePlayer,name,month,day,year,mail) 
        local update = executeSQLQuery("UPDATE Profile SET name='"..name.."', month='"..month.."', day='"..day.."', year='"..year.."', mail='"..mail.."' WHERE player='"..getAccountName(getPlayerAccount(source)).."'") 
        triggerEvent('onSaveOutput',source) 
    end 
) 

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

Hey! I have another problem about this. If I reconnect and I'm logged in it appears but if I logout and login again or restart resource the text not appears anymore :S

Client-side:

addEventHandler('onClientGUIClick',root, 
    function() 
        if source == gui['button1_name'] then 
            guiSetVisible(profile['window'],not guiGetVisible(profile['window'])) 
  
        elseif source == profile['save_label'] then 
            triggerServerEvent('onClickSave',localPlayer,getPlayerName(localPlayer),guiGetText(profile['name_memo']),guiGetText(profile['birthday_m']),guiGetText(profile['birthday_d']),guiGetText(profile['birthday_y']),guiGetText(profile['mail_memo']),getElementData(localPlayer,'Image')) 
            triggerServerEvent('onSaveSettings',localPlayer) 
  
        elseif source == profile['img_choose'] then 
            guiSetVisible(profile['window'],false) 
            guiSetVisible(profile['img'],true) 
  
        elseif source == profile['img_select'] then 
            local row, col = guiGridListGetSelectedItem(source) 
            if row and col and row ~= -1 and col ~= -1 then 
                local dir = guiGridListGetItemData(source,row, col) 
                guiStaticImageLoadImage(profile['img_preview'],dir) 
            end 
  
        elseif source == profile['cancel'] then 
            guiSetVisible(profile['img'],false) 
            guiSetVisible(profile['window'],true) 
            showCursor(true) 
  
        elseif source == profile['set'] then 
            local row, col = guiGridListGetSelectedItem(profile['img_select']) 
            if row and col and row ~= -1 and col ~= -1 then 
                local dir = guiGridListGetItemData(profile['img_select'],row, col) 
                guiStaticImageLoadImage(profile['image'],dir) 
                setElementData(localPlayer,'Image',dir) 
                guiSetVisible(profile['img'],false) 
                guiSetVisible(profile['window'],true) 
            end 
  
        end 
    end 
) 
  
addEventHandler('onLoginLoad',root, 
    function(name,month,day,year,mail,image) 
        guiSetText(profile['name_memo'],name) 
        guiSetText(profile['birthday_m'],month) 
        guiSetText(profile['birthday_d'],day) 
        guiSetText(profile['birthday_y'],year) 
        guiSetText(profile['mail_memo'],mail) 
        guiStaticImageLoadImage(profile['image'],image) 
    end 
) 
  

Server-side:

    --[[ 
        --@@author Draken 
        --@@18-02-2012 
    ]]-- 
  
    local table = executeSQLQuery("CREATE TABLE IF NOT EXISTS Profile ( player TEXT, name TEXT, month NUMBER, day NUMBER, year NUMBER, mail TEXT, image TEXT )") 
  
    addEvent('onPlayerNotLoggedIn',true) 
    addEvent('isPlayerGuest',true) 
    addEvent('onSaveSettings',true) 
    addEvent('onSaveOutput',true) 
    addEvent('onClickSave',true) 
  
    addEventHandler('isPlayerGuest',root, 
     function() 
        local account = getPlayerAccount(source) 
            if not isGuestAccount(account) then 
                triggerClientEvent('onPanelOpen',source) 
            else 
                triggerEvent('onPlayerNotLoggedIn',source) 
        end 
    end) 
  
    addEventHandler('onPlayerNotLoggedIn',root, 
        function() 
            outputChatBox("#ABCDEF* #ffffffYou are not logged in!",source,255,255,255,true) 
        end 
    ) 
  
    addEventHandler('onSaveOutput',root, 
        function() 
            outputChatBox('#ABCDEF* #ffffffYour settings have been saved!',source,255,255,255,true) 
        end 
    ) 
  
    addEventHandler('onPlayerLogin',root, 
        function (_, account) 
            local result = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(account).."'") 
            if (not result or #result == 0) then 
                executeSQLQuery("INSERT INTO Profile VALUES ( '"..getAccountName(account).."', '', 'Month', 'Day', 'Year', '', '' )") 
            end 
            local resultt = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(account).."'") 
            triggerClientEvent('onLoginLoad',source,tostring(resultt[1]['name']),tostring(resultt[1]['month']),tostring(resultt[1]['day']),tostring(resultt[1]['year']),tostring(resultt[1]['mail']),tostring(resultt[1]['image'])) 
        end 
    ) 
  
    addEventHandler('onClickSave',root, 
        function(thePlayer,name,month,day,year,mail,image) 
            local update = executeSQLQuery("UPDATE Profile SET name='"..name.."', month='"..month.."', day='"..day.."', year='"..year.."', mail='"..mail.."', image='"..image.."' WHERE player='"..getAccountName(getPlayerAccount(source)).."'") 
            triggerEvent('onSaveOutput',source) 
        end 
    ) 
  

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

It's too long. About 300 lines :S

I will show only the profile part.

Client-side:

--profile choose image 
  
profile['img'] = guiCreateStaticImage((268/800)*sx,(98/600)*sy,(395/800)*sx,(309/600)*sy,"_utils/_data/_image/grid.png",false) 
profile['img_select'] = guiCreateGridList((32/800)*sx,(19/600)*sy,(153/800)*sx,(268/600)*sy,false,profile['img']) 
guiGridListSetSelectionMode(profile['img_select'],0) 
guiSetAlpha(profile['img_select'],0.-- s8) -->
  
profile['img_preview'] = guiCreateStaticImage((208/800)*sx,(30/600)*sy,(157/800)*sx,(199/600)*sy,"_utils/_data/_image/radar.png",false,profile['img']) 
profile['set'] = guiCreateButton((200/800)*sx,(249/600)*sy,(82/800)*sx,(27/600)*sy,"Set",false,profile['img']) 
guiSetAlpha(profile['set'],0.9) 
profile['cancel'] = guiCreateButton((288/800)*sx,(248/600)*sy,(82/800)*sx,(27/600)*sy,"Cancel",false,profile['img']) 
guiSetAlpha(profile['cancel'],0.9) 
  
local column = guiGridListAddColumn(profile['img_select'],'Image',0.-- s8) -->
if column then 
    for name, dir in pairs(imageList) do 
        local row = guiGridListAddRow(profile['img_select']) 
        guiGridListSetItemText(profile['img_select'],row,column,tostring(name),false,false) 
        guiGridListSetItemData(profile['img_select'],row,column,tostring(dir)) 
    end 
end 
  
--main script 
  
guiSetVisible(gui['window'],false) 
guiSetVisible(profile['window'],false) 
guiSetVisible(profile['img'],false) 
  
  
addEventHandler('onClientGUIClick',root, 
    function() 
        if source == gui['button1_name'] then 
            guiSetVisible(profile['window'],not guiGetVisible(profile['window'])) 
  
        elseif source == profile['save_label'] then 
            triggerServerEvent('onClickSave',localPlayer,getPlayerName(localPlayer),guiGetText(profile['name_memo']),guiGetText(profile['birthday_m']),guiGetText(profile['birthday_d']),guiGetText(profile['birthday_y']),guiGetText(profile['mail_memo']),getElementData(localPlayer,'Image')) 
            triggerServerEvent('onSaveSettings',localPlayer) 
  
        elseif source == profile['img_choose'] then 
            guiSetVisible(profile['window'],false) 
            guiSetVisible(profile['img'],true) 
  
        elseif source == profile['img_select'] then 
            local row, col = guiGridListGetSelectedItem(source) 
            if row and col and row ~= -1 and col ~= -1 then 
                local dir = guiGridListGetItemData(source,row, col) 
                guiStaticImageLoadImage(profile['img_preview'],dir) 
            end 
  
        elseif source == profile['cancel'] then 
            guiSetVisible(profile['img'],false) 
            guiSetVisible(profile['window'],true) 
            showCursor(true) 
  
        elseif source == profile['set'] then 
            local row, col = guiGridListGetSelectedItem(profile['img_select']) 
            if row and col and row ~= -1 and col ~= -1 then 
                local dir = guiGridListGetItemData(profile['img_select'],row, col) 
                guiStaticImageLoadImage(profile['image'],dir) 
                setElementData(localPlayer,'Image',dir) 
                guiSetVisible(profile['img'],false) 
                guiSetVisible(profile['window'],true) 
            end 
  
        end 
    end 
) 
  
addEventHandler('onLoginLoad',root, 
    function(name,month,day,year,mail,image) 
        guiSetText(profile['name_memo'],name) 
        guiSetText(profile['birthday_m'],month) 
        guiSetText(profile['birthday_d'],day) 
        guiSetText(profile['birthday_y'],year) 
        guiSetText(profile['mail_memo'],mail) 
        guiStaticImageLoadImage(profile['image'],image) 
    end 
) 
  

Server-side:

    --[[ 
        --@@author Draken 
        --@@18-02-2012 
    ]]-- 
  
    local table = executeSQLQuery("CREATE TABLE IF NOT EXISTS Profile ( player TEXT, name TEXT, month NUMBER, day NUMBER, year NUMBER, mail TEXT, image TEXT )") 
  
    addEvent('onPlayerNotLoggedIn',true) 
    addEvent('isPlayerGuest',true) 
    addEvent('onSaveSettings',true) 
    addEvent('onSaveOutput',true) 
    addEvent('onClickSave',true) 
  
    addEventHandler('isPlayerGuest',root, 
     function() 
        local account = getPlayerAccount(source) 
            if not isGuestAccount(account) then 
                triggerClientEvent('onPanelOpen',source) 
            else 
                triggerEvent('onPlayerNotLoggedIn',source) 
        end 
    end) 
  
    addEventHandler('onPlayerNotLoggedIn',root, 
        function() 
            outputChatBox("#ABCDEF* #ffffffYou are not logged in!",source,255,255,255,true) 
        end 
    ) 
  
    addEventHandler('onSaveOutput',root, 
        function() 
            outputChatBox('#ABCDEF* #ffffffYour settings have been saved!',source,255,255,255,true) 
        end 
    ) 
  
    addEventHandler('onPlayerLogin',root, 
        function (_, account) 
            local result = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(account).."'") 
            if (not result or #result == 0) then 
                executeSQLQuery("INSERT INTO Profile VALUES ( '"..getAccountName(account).."', '', 'Month', 'Day', 'Year', '', '' )") 
            end 
            local resultt = executeSQLQuery("SELECT * FROM Profile WHERE player = '"..getAccountName(account).."'") 
            triggerClientEvent('onLoginLoad',source,tostring(resultt[1]['name']),tostring(resultt[1]['month']),tostring(resultt[1]['day']),tostring(resultt[1]['year']),tostring(resultt[1]['mail']),tostring(resultt[1]['image'])) 
        end 
    ) 
  
    addEventHandler('onClickSave',root, 
        function(thePlayer,name,month,day,year,mail,image) 
            local update = executeSQLQuery("UPDATE Profile SET name='"..name.."', month='"..month.."', day='"..day.."', year='"..year.."', mail='"..mail.."', image='"..image.."' WHERE player='"..getAccountName(getPlayerAccount(source)).."'") 
            triggerEvent('onSaveOutput',source) 
        end 
    ) 
  

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted
Hey! I have another problem about this. If I reconnect and I'm logged in it appears but if I logout and login again or restart resource the text not appears anymore :S

1.onResourceStart --> trigger Client event onLoginLoad.

2.if player logout you destroy guis?

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted
Hey! I have another problem about this. If I reconnect and I'm logged in it appears but if I logout and login again or restart resource the text not appears anymore :S

1.onResourceStart --> trigger Client event onLoginLoad.

2.if player logout you destroy guis?

1.onResourceStart --> trigger Client event onLoginLoad. I will try :lol:

2.if player logout you destroy guis? Not :shock:

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

I think that now it working. If not, I post the code.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

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