Mysql Problem ( cache_insert_id )
#1

Hi everyone , i'am now creating register/login system and i got a problem with registration , so when i'am logged in with account that i have created ( for example Account ID 17 ) , then i disconnect and reconnect with new account that i will create it In game , i got the same 'CompteID' and when my account save , the stats of my new account will be in the old account, check my PlayerFile_Create

PHP код:
forward PlayerFile_Create(playerid);
public 
PlayerFile_Create(playerid)
{
    
APlayerData[playerid][CompteID] = cache_insert_id();
    
printf("ETAT DU SERVEUR: ENREGISTREMENT D'UN COMPTE ID : %d"APlayerData[playerid][CompteID]);
    return 
1;

Save :

PHP код:
forward PlayerFile_Save(playerid);
public 
PlayerFile_Save(playerid)
{
    new 
query[1024]; 
    
format(querysizeof(query), "UPDATE `users` SET `Level` = %d,"APlayerData[playerid][PlayerLevel]);
    
format(querysizeof(query), "%s `VIP` = %d, `Jailed` = %d, `Wanted` = %d,"queryAPlayerData[playerid][VIPLevel], APlayerData[playerid][PlayerJailed], GetPlayerWantedLevel(playerid));
    
format(querysizeof(query), "%s `Bans` = %d, `BanTime` = %d, `TruckerLicense` = %d,"queryAPlayerData[playerid][Bans], APlayerData[playerid][BanTime], APlayerData[playerid][TruckerLicense]);
    
format(querysizeof(query), "%s `BusLicense` = %d, `PilotLicense` = %d,"queryAPlayerData[playerid][BusLicense], APlayerData[playerid][PilotLicense]);
    
format(querysizeof(query), "%s `MafiaLicense` = %d, `Muted` = %d,"queryAPlayerData[playerid][MafiaLicense], APlayerData[playerid][Muted]);
    
format(querysizeof(query), "%s `RulesRead` = %d, `StatsMetersDriven` = %d, `LastLoggin` = %d,"queryAPlayerData[playerid][RulesRead], APlayerData[playerid][StatsMetersDriven], ReturnDate());
    
format(querysizeof(query), "%s `StatsTruckerJobs` = %d, `StatsConvoyJobs` = %d,"queryAPlayerData[playerid][StatsTruckerJobs], APlayerData[playerid][StatsConvoyJobs]);
    
format(querysizeof(query), "%s `StatsBusDriverJobs` = %d, `StatsPilotJobs` = %d,"queryAPlayerData[playerid][StatsBusDriverJobs], APlayerData[playerid][StatsPilotJobs]);
    
format(querysizeof(query), "%s `StatsMafiaJobs` = %d, `StatsMafiaStolen` = %d,"queryAPlayerData[playerid][StatsMafiaJobs], APlayerData[playerid][StatsMafiaStolen]);
    
format(querysizeof(query), "%s `StatsPoliceFined` = %d, `StatsPoliceJailed` = %d,"queryAPlayerData[playerid][StatsPoliceFined], APlayerData[playerid][StatsPoliceJailed]);
    
format(querysizeof(query), "%s `StatsCourierJobs` = %d, `StatsRoadworkerJobs` = %d,"queryAPlayerData[playerid][StatsCourierJobs], APlayerData[playerid][StatsRoadworkerJobs]);
    
format(querysizeof(query), "%s `StatsAssistance` = %d, `Team` = %d, `Leader` = %d,"queryAPlayerData[playerid][StatsAssistance], APlayerData[playerid][Team], APlayerData[playerid][Leader]);
    
format(querysizeof(query), "%s `Heuresjouer` = %d, `Minutesjouer` = %d,"queryAPlayerData[playerid][pHeures], APlayerData[playerid][pMinutes]);
    
format(querysizeof(query), "%s `Money` = %d, `Score` = %d WHERE `ID` = %d"queryAPlayerData[playerid][PlayerMoney], APlayerData[playerid][PlayerScore], APlayerData[playerid][CompteID]);
    
mysql_format(g_iHandlequerysizeof(query), "%s"query);
    
mysql_tquery(g_iHandlequery); 
    
printf("STATS DU SERVEUR | ENREGISTREMENT MYSQL : %s"query);
    return 
1;

Thank's for reading.
Reply
#2

Is the "ID" field set with auto increment in the table structure?
Reply
#3

Yes it is.

PHP код:

CREATE TABLE 
IF NOT EXISTS `users` (
  `
IDint(12NOT NULL AUTO_INCREMENT
PHP код:
  PRIMARY KEY (`ID`) 
Reply
#4

I can only think of 2 things (not sure about the second one though):

- In INSERT query, ID is given a value instead of being NULL.
- Multiply connections have different connection handle so using "1" as default might conflict.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I can only think of 2 things (not sure about the second one though):

- In INSERT query, ID is given a value instead of being NULL.
- Multiply connections have different connection handle so using "1" as default might conflict.
When i connect with old account that i have create it , i got ID 17 , i disconnect everything is OK , all work in save system , then i reconnect with new name that it's not register in database i create account and i disconnect second time the second account will take ID 17 and everything in the old account will take the stats of the new account ( everything will be 0 because it's a new account ).
Reply
#6

i think problem can be here ( in registration dialog )

PHP код:
Dialog_Register(playeridresponsepasswordtext[])
{
    new 
file[100], Name[MAX_PLAYER_NAME]; // Setup local variables
    
GetPlayerName(playeridNamesizeof(Name)); // Get the playername
    
format(filesizeof(file), PlayerFileName); // Construct the complete filename for this player's account
    
switch (response// Check which button was clicked
    
{
        case 
1// Player clicked "Register"
        
{
            
// Check if the player entered a password
            
if(strlen(passwordtext) > 0)
            {
                new 
query[300];
                
// mysql_format(g_iHandle, query, sizeof(query), "INSERT INTO `users` (`PlayerName`, `Password`) VALUES ('%e', '%s')", GetPlayerNameEx(playerid), passwordtext);
                
mysql_format(g_iHandlequerysizeof(query), "INSERT INTO `users` (`PlayerName`, `Password`, `email`) VALUES ('%e', '%s', '%s')"GetPlayerNameEx(playerid), passwordtextAPlayerData[playerid][Email]);
                
mysql_tquery(g_iHandlequery"""i"playerid);
                
                
// Send a message to the client to inform him that his account has been registered
                
SendClientMessage(playerid0xFFFFFFFFTXT_AccountRegistered);
                
APlayerData[playerid][LoggedIn] = true// The player has logged in properly
            
}
            else
            {
                
SendClientMessage(playerid0xFFFFFFFFTXT_WrongPassword);
                
KickEx(playerid);
            }
        }
        case 
0// Player clicked "Cancel"
        
{
            
// Show a message that the player must be registered to play on this server
            
SendClientMessage(playerid0xFFFFFFFFTXT_PlayerMustRegister);
            
// Kick the player
            
KickEx(playerid);
        }
    }
    return 
1;

EDIT :

i didn't use "PlayerFile_Create" anywhere.
Reply
#7

Yes, you didn't.
pawn Код:
mysql_tquery(g_iHandle, query, "PlayerFile_Create", "i", playerid);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)