Raised This Month: $32 Target: $400
 8% 

SQL Insert and Update Player Info


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xRENN1Ex
Junior Member
Join Date: Dec 2019
Old 12-28-2019 , 03:17   SQL Insert and Update Player Info
Reply With Quote #1

Player info is registering MYSQL to update, but does not update. Can you help me?

(ip, name, authid, hp, alive or dead

Code:
new Handle:Query = SQL_PrepareQuery(SqlConnection, "INSERT INTO `playerlogger` (`ip`, `name`, `authid`, `hp`, `df_canli`) VALUES  ('%s','%s','%s','%i','%i') ON DUPLICATE KEY UPDATE `ip`=VALUES(`ip`), `name`=VALUES(`name`), `authid`=VALUES(`authid`), `hp`=VALUES(`hp`), `df_canli`=VALUES(`df_canli`);", szIP, szName, szAuthid, iL_HP, df_canli);
Attached Files
File Type: sma Get Plugin or Get Source (playerInfoSaveDB.sma - 159 views - 2.1 KB)

Last edited by xRENN1Ex; 12-28-2019 at 03:17.
xRENN1Ex is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-28-2019 , 06:51   Re: SQL Insert and Update Player Info
Reply With Quote #2

Do debugging and see where your code fails.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 12-28-2019 , 07:16   Re: SQL Insert and Update Player Info
Reply With Quote #3

This query is totally wrong. Why you supposed to updated inserted record?
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
xRENN1Ex
Junior Member
Join Date: Dec 2019
Old 12-28-2019 , 08:05   Re: SQL Insert and Update Player Info
Reply With Quote #4

Can you do the right thing?
Because players want to reflect the view. You can look here as an example

https://www.csduragi.com/monitor/cs8.csduragi.net
xRENN1Ex is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-28-2019 , 10:54   Re: SQL Insert and Update Player Info
Reply With Quote #5

Use replace instead .
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
xRENN1Ex
Junior Member
Join Date: Dec 2019
Old 12-28-2019 , 11:37   Re: SQL Insert and Update Player Info
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
Use replace instead .


can you give me information about how to use it?
xRENN1Ex is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-28-2019 , 13:37   Re: SQL Insert and Update Player Info
Reply With Quote #7

You need to include a primary key in the statement otherwise it will work the same as insert. If any fields in the record have a value then you must include them in the statement, even if they are not being changed, otherwise they will be set to null. In the below example my primary key in the table is ID, set to auto-increment to make inserting new records easy.

Suppose I have the below record:

ID = 223
SteamID = STEAM_0:1:12345
PlayerName= bugsy
PlayTime= 555

I can then do the below to update PlayTime to 123. Fields SteamID & PlayerName will remain unchanged since I am including the existing values in the statement.

Code:
REPLACE INTO tblPlayerData (ID, SteamID, PlayerName, PlayTime) VALUES (223,'STEAM_0:0:12345','bugsy',123);
If I also have a column XPPoints in the table, it would be set to null with the above REPLACE INTO statement, unless I specify a value.

Assume these fields exist in a row:

ID = 223
SteamID = STEAM_0:1:12345
PlayerName= bugsy
PlayTime= 555
XPPoints = 555

Code:
REPLACE INTO tblPlayerData (ID, SteamID, PlayerName, PlayTime, XPPoints) VALUES (223,'STEAM_0:0:12345','bugsy',123,555);
This will retain XPPoints value of 555 (and leave SteamID & PlayerName as is), while changing PlayTime to 123.

When adding a new record, just exclude the ID field and it will add a new record, advancing ID to the next slot automatically.

Code:
REPLACE INTO tblPlayerData (SteamID, PlayerName) VALUES ('STEAM_0:0:555','bugsy2');
__________________

Last edited by Bugsy; 12-28-2019 at 14:21.
Bugsy is offline
xRENN1Ex
Junior Member
Join Date: Dec 2019
Old 12-28-2019 , 15:13   Re: SQL Insert and Update Player Info
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
You need to include a primary key in the statement otherwise it will work the same as insert. If any fields in the record have a value then you must include them in the statement, even if they are not being changed, otherwise they will be set to null. In the below example my primary key in the table is ID, set to auto-increment to make inserting new records easy.

Suppose I have the below record:

ID = 223
SteamID = STEAM_0:1:12345
PlayerName= bugsy
PlayTime= 555

I can then do the below to update PlayTime to 123. Fields SteamID & PlayerName will remain unchanged since I am including the existing values in the statement.

Code:
REPLACE INTO tblPlayerData (ID, SteamID, PlayerName, PlayTime) VALUES (223,'STEAM_0:0:12345','bugsy',123);
If I also have a column XPPoints in the table, it would be set to null with the above REPLACE INTO statement, unless I specify a value.

Assume these fields exist in a row:

ID = 223
SteamID = STEAM_0:1:12345
PlayerName= bugsy
PlayTime= 555
XPPoints = 555

Code:
REPLACE INTO tblPlayerData (ID, SteamID, PlayerName, PlayTime, XPPoints) VALUES (223,'STEAM_0:0:12345','bugsy',123,555);
This will retain XPPoints value of 555 (and leave SteamID & PlayerName as is), while changing PlayTime to 123.

When adding a new record, just exclude the ID field and it will add a new record, advancing ID to the next slot automatically.

Code:
REPLACE INTO tblPlayerData (SteamID, PlayerName) VALUES ('STEAM_0:0:555','bugsy2');


thank you for the answer

so can you ask me to do this sma coding

I don't have many resources because I am Turkish so I will be forced

I need help because it has a different structure than php
xRENN1Ex is offline
xRENN1Ex
Junior Member
Join Date: Dec 2019
Old 12-28-2019 , 16:59   Re: SQL Insert and Update Player Info
Reply With Quote #9

Code:
public RegisterUser(id){
    new szIP[32],szName[32],szAuthid[32],h_Healts,a_Alive;
    get_user_ip(id,szIP,charsmax(szIP), 1)
    get_user_name(id,szName,charsmax(szName))
    get_user_authid(id,szAuthid,charsmax(szAuthid))
    h_Healts = get_user_health(id)
    a_Alive = is_user_alive(id)
    
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
    if(SqlConnection == Empty_Handle)
        set_fail_state(g_Error)

  	new Handle:Query = SQL_PrepareQuery(SqlConnection, "INSERT INTO `playerlogger` (`ip`, `name`, `authid`, `h_Healts`, `a_Alive`) VALUES  ('%s','%s','%s','%i','%i') ON DUPLICATE KEY UPDATE `playerlogger` SET `h_Healts` = REPLACE(`h_Healts`, `h_Healts`, `99`);", szIP, szName, szAuthid, h_Healts, a_Alive);
    

    if(!SQL_Execute(Query)){
        SQL_QueryError(Query,g_Error,511)
        set_fail_state(g_Error)
    }
    
    SQL_FreeHandle(Query)
    SQL_FreeHandle(SqlConnection)
}
is this code block correct?
xRENN1Ex is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode