MYSQL EROR

Započeo Bandit234, Jul 18, 2022, 14:25:59 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 1 gost pregledaju ovu temu.

Problem(error/warning): [13:28:16] [ERROR] error #1062 while executing query "INSERT INTO `korisnici` (Ime,Lozinka) VALUES('Jasmin_Bilic', '49') ": Duplicate entry '0' for key 'PRIMARY'

Deo skripte: [pawn]
enum pInfo
{
   SQLID,
   Ime[MAX_PLAYER_NAME],
   Lozinka,
   Skin,
   Level,
   Respekti,
   Novac,
   Spol,
   Godine,
   Drzava
};
new PlayerInfo[MAX_PLAYERS][pInfo];

new bool:Ulogovan[MAX_PLAYERS];

enum
{
   DIALOG_REGISTER,
   DIALOG_LOGIN,
   DIALOG_SPOL,
   DIALOG_GODINE,
   DIALOG_DRZAVA
};

new MySQL:SQL;

stock GetName(playerid)
{
   new name[MAX_PLAYER_NAME];
   GetPlayerName(playerid, name,sizeof(name));
   return name;
}

stock udb_hash(buf[])
{
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

main()
{
   print("BosniaSQL beta je ocitan");
}

public OnGameModeInit()
{
   SQL = mysql_connect(MYSQL_HOST,MYSQL_USER,"",MYSQL_DB);
   if(mysql_errno(SQL) != 0 || SQL == MYSQL_INVALID_HANDLE)
   {
        print("Mod nije uspjesno povezan sa databazom, gasim server");
        SendRconCommand("exit");
        return 1;
    }
   print("Uspjesno povezivanje moda sa bazom");
   DisableInteriorEnterExits();
   ShowPlayerMarkers(false);
   EnableStuntBonusForAll(false);
   return 1;
}
public OnPlayerConnect(playerid)
{
   PlayerInfo[playerid][SQLID] = -1;
   Ulogovan[playerid] = false;
   new query[500];
   mysql_format(SQL,query,sizeof(query),"SELECT * FROM `korisnici` WHERE  `Ime` = '%e' LIMIT 1",GetName(playerid));
   mysql_tquery(SQL,query,"SQL_Provjera","i",playerid);
   return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
   PlayerInfo[playerid][SQLID] = -1;
   Ulogovan[playerid] = false;
   return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
   switch(dialogid)
   {
      case DIALOG_LOGIN:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            if(udb_hash(inputtext) == PlayerInfo[playerid][Lozinka])
            {
               if(Ulogovan[playerid] == true)return SCM(playerid,COLOR_RED,"Vi ste vec ulogovani");
               SetPlayerSkin(playerid, PlayerInfo[playerid][Skin]);
               TogglePlayerSpectating(playerid,false);
               SetPlayerScore(playerid, PlayerInfo[playerid][Level]);
               ResetPlayerMoney(playerid);
               ResetPlayerWeapons(playerid);
               OcistiChat(playerid,25);
               Ulogovan[playerid] = true;
               SCM(playerid,COLOR_LIME,"Uspjesno ste se ulogovali");
                SetSpawnInfo(playerid,0,PlayerInfo[playerid][Skin],0.0,0.0,0.0,0.0,0,0,0,0,0,0);
                SpawnPlayer(playerid);
            }
            else
            {
               ShowPlayerDialog(playerid, DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Upisite svoju lozinku","Uloguj se","Odustani");
            }
         }
      }
      case DIALOG_REGISTER:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            if(strlen(inputtext) < 10 ||strlen(inputtext) > 65)
            {
               SCM(playerid,COLOR_RED,"Lozinka vam je kraca od 10 ili duza od 65 karaktera!");
               ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Registracija","Vasa lozinka moze biti samo manja 10 a ne duza od 65 ","Nasavi","Odustani");
            }
            PlayerInfo[playerid][Lozinka] = udb_hash(inputtext);
            new query[500];
            mysql_format(SQL,query,sizeof(query),"INSERT INTO `korisnici` (Ime,Lozinka) VALUES('%e', '%d') ",GetName(playerid),inputtext);
            mysql_tquery(SQL, query,"insertSQLID","d",playerid);

            ShowPlayerDialog(playerid,DIALOG_SPOL,DIALOG_STYLE_LIST,"Spol","Musko\nZensko","Unesi","Odustani");
         }
      }
      case DIALOG_SPOL:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            switch(listitem)
            {
               case 0:
               {
                  PlayerInfo[playerid][Spol] = 0;
                  SCM(playerid,COLOR_LIME,"Vi ste musko!");
               }
               case 1:
               {
                  PlayerInfo[playerid][Spol] = 1;
                  SCM(playerid,COLOR_LIME,"Vi ste zensko!");
               }
            }
            new query[500];
            mysql_format(SQL,query,sizeof(query),"UPDATE `korisnici` SET `Spol` = '%d' WHERE `ID` = '%d' ",PlayerInfo[playerid][Spol],PlayerInfo[playerid][SQLID]);
            mysql_tquery(SQL,query);
            ShowPlayerDialog(playerid,DIALOG_DRZAVA,DIALOG_STYLE_LIST,"Drzava","Bih\nHrvatska\nSrbija\nCrna Gora\nMakedonija\nSlovenija\nOstalo","Unesi","Odustani");
         }
      }
      case DIALOG_DRZAVA:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            switch(listitem)
            {
               case 0:
               {
                  PlayerInfo[playerid][Drzava] = 0;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Bih!");
               }
               case 1:
               {
                  PlayerInfo[playerid][Drzava] = 1;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Hrvatska!");
               }
               case 2:
               {
                  PlayerInfo[playerid][Drzava] = 2;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Srbija!");
               }
               case 3:
               {
                  PlayerInfo[playerid][Drzava] = 3;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Crna Gora!");
               }
               case 4:
               {
                  PlayerInfo[playerid][Drzava] = 4;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Makedonije!");
               }
               case 5:
               {
                  PlayerInfo[playerid][Drzava] = 5;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Slovenija!");
               }
               case 6:
               {
                  PlayerInfo[playerid][Drzava] = 6;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Ostalo!");
               }
            }
            new query[500];
            mysql_format(SQL,query,sizeof(query),"UPDATE `korisnici` SET `Drzava` = '%d' WHERE `ID` = '%d' ",PlayerInfo[playerid][Drzava],PlayerInfo[playerid][SQLID]);
            mysql_tquery(SQL,query);
            ShowPlayerDialog(playerid,DIALOG_GODINE,DIALOG_STYLE_INPUT,"Godine","Unesite vase godine!","Unesi","Odustani");
         }
      }
      case DIALOG_GODINE:
      {
         new god = strval(inputtext);
          if(god < 10)return ShowPlayerDialog(playerid, DIALOG_GODINE, DIALOG_STYLE_INPUT,"Unesite godine", "Godine ne mogu biti manje od 10 i vise od 65","Unesi", "Odustani");
          if(god > 65)return ShowPlayerDialog(playerid, DIALOG_GODINE, DIALOG_STYLE_INPUT,"Unesite godine", "Godine ne mogu biti manje od 10 i vise od 65","Unesi", "Odustani");
          PlayerInfo[playerid][Godine] = god;
          new query[500];
         mysql_format(SQL,query,sizeof(query),"UPDATE `korisnici` SET `Godine` = '%d' WHERE `ID` = '%d' ",PlayerInfo[playerid][Godine],PlayerInfo[playerid][SQLID]);
         mysql_tquery(SQL,query);
          SetSpawnInfo(playerid,0,PlayerInfo[playerid][Skin],0.0,0.0,0.0,0.0,0,0,0,0,0,0);
          SpawnPlayer(playerid);
          Ulogovan[playerid] = true;

      }
   }
   return 1;
}
forward insertSQLID(playerid);
public insertSQLID(playerid)
{
   PlayerInfo[playerid][SQLID] = cache_insert_id();
   printf("Kreiran nalog SQLID %d IME %s",PlayerInfo[playerid][SQLID],GetName(playerid));
   return 1;
}

forward SQL_Provjera(playerid);
public SQL_Provjera(playerid)
{
   switch(cache_num_rows())
   {
      case 0:
      {
         ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Registracija","Vasa lozinka moze biti samo manja 10 a ne duza od 65 ","Nasavi","Odustani");
      }
      case 1:
      {
         cache_get_value_name_int(0,"ID",PlayerInfo[playerid][SQLID]);
         cache_get_value_name(0,"Ime",PlayerInfo[playerid][Ime]);
         cache_get_value_name_int(0,"Lozinka",PlayerInfo[playerid][Lozinka]);
         cache_get_value_name_int(0,"Spol",PlayerInfo[playerid][Spol]);
         cache_get_value_name_int(0,"Drzava",PlayerInfo[playerid][Drzava]);
         cache_get_value_name_int(0,"Godine",PlayerInfo[playerid][Godine]);
         cache_get_value_name_int(0,"Novac",PlayerInfo[playerid][Novac]);
         cache_get_value_name_int(0,"Level",PlayerInfo[playerid][Level]);
         cache_get_value_name_int(0,"Respekti",PlayerInfo[playerid][Respekti]);
         cache_get_value_name_int(0,"Skin",PlayerInfo[playerid][Skin]);
         ShowPlayerDialog(playerid, DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Upisite svoju lozinku","Uloguj se","Odustani");
      }
   }
}

[/pawn]
Debug iz server_log(ukoliko je u pitanju crashanje servera - crashdetect log): [pawn]//[/pawn]
Slika/video ingame problema(obavezno ako je ingame problem): //
Poslednja Izmena: Jul 18, 2022, 21:16:01 POSLE PODNE od Deleted User

Citat: Bandit234 poslato Jul 18, 2022, 14:25:59 POSLE PODNE
Problem(error/warning): [13:28:16] [ERROR] error #1062 while executing query "INSERT INTO `korisnici` (Ime,Lozinka) VALUES('Jasmin_Bilic', '49') ": Duplicate entry '0' for key 'PRIMARY'

Deo skripte: [pawn]
enum pInfo
{
   SQLID,
   Ime[MAX_PLAYER_NAME],
   Lozinka,
   Skin,
   Level,
   Respekti,
   Novac,
   Spol,
   Godine,
   Drzava
};
new PlayerInfo[MAX_PLAYERS][pInfo];

new bool:Ulogovan[MAX_PLAYERS];

enum
{
   DIALOG_REGISTER,
   DIALOG_LOGIN,
   DIALOG_SPOL,
   DIALOG_GODINE,
   DIALOG_DRZAVA
};

new MySQL:SQL;

stock GetName(playerid)
{
   new name[MAX_PLAYER_NAME];
   GetPlayerName(playerid, name,sizeof(name));
   return name;
}

stock udb_hash(buf[])
{
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

main()
{
   print("BosniaSQL beta je ocitan");
}

public OnGameModeInit()
{
   SQL = mysql_connect(MYSQL_HOST,MYSQL_USER,"",MYSQL_DB);
   if(mysql_errno(SQL) != 0 || SQL == MYSQL_INVALID_HANDLE)
   {
        print("Mod nije uspjesno povezan sa databazom, gasim server");
        SendRconCommand("exit");
        return 1;
    }
   print("Uspjesno povezivanje moda sa bazom");
   DisableInteriorEnterExits();
   ShowPlayerMarkers(false);
   EnableStuntBonusForAll(false);
   return 1;
}
public OnPlayerConnect(playerid)
{
   PlayerInfo[playerid][SQLID] = -1;
   Ulogovan[playerid] = false;
   new query[500];
   mysql_format(SQL,query,sizeof(query),"SELECT * FROM `korisnici` WHERE  `Ime` = '%e' LIMIT 1",GetName(playerid));
   mysql_tquery(SQL,query,"SQL_Provjera","i",playerid);
   return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
   PlayerInfo[playerid][SQLID] = -1;
   Ulogovan[playerid] = false;
   return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
   switch(dialogid)
   {
      case DIALOG_LOGIN:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            if(udb_hash(inputtext) == PlayerInfo[playerid][Lozinka])
            {
               if(Ulogovan[playerid] == true)return SCM(playerid,COLOR_RED,"Vi ste vec ulogovani");
               SetPlayerSkin(playerid, PlayerInfo[playerid][Skin]);
               TogglePlayerSpectating(playerid,false);
               SetPlayerScore(playerid, PlayerInfo[playerid][Level]);
               ResetPlayerMoney(playerid);
               ResetPlayerWeapons(playerid);
               OcistiChat(playerid,25);
               Ulogovan[playerid] = true;
               SCM(playerid,COLOR_LIME,"Uspjesno ste se ulogovali");
                SetSpawnInfo(playerid,0,PlayerInfo[playerid][Skin],0.0,0.0,0.0,0.0,0,0,0,0,0,0);
                SpawnPlayer(playerid);
            }
            else
            {
               ShowPlayerDialog(playerid, DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Upisite svoju lozinku","Uloguj se","Odustani");
            }
         }
      }
      case DIALOG_REGISTER:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            if(strlen(inputtext) < 10 ||strlen(inputtext) > 65)
            {
               SCM(playerid,COLOR_RED,"Lozinka vam je kraca od 10 ili duza od 65 karaktera!");
               ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Registracija","Vasa lozinka moze biti samo manja 10 a ne duza od 65 ","Nasavi","Odustani");
            }
            PlayerInfo[playerid][Lozinka] = udb_hash(inputtext);
            new query[500];
            mysql_format(SQL,query,sizeof(query),"INSERT INTO `korisnici` (Ime,Lozinka) VALUES('%e', '%d') ",GetName(playerid),inputtext);
            mysql_tquery(SQL, query,"insertSQLID","d",playerid);

            ShowPlayerDialog(playerid,DIALOG_SPOL,DIALOG_STYLE_LIST,"Spol","Musko\nZensko","Unesi","Odustani");
         }
      }
      case DIALOG_SPOL:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            switch(listitem)
            {
               case 0:
               {
                  PlayerInfo[playerid][Spol] = 0;
                  SCM(playerid,COLOR_LIME,"Vi ste musko!");
               }
               case 1:
               {
                  PlayerInfo[playerid][Spol] = 1;
                  SCM(playerid,COLOR_LIME,"Vi ste zensko!");
               }
            }
            new query[500];
            mysql_format(SQL,query,sizeof(query),"UPDATE `korisnici` SET `Spol` = '%d' WHERE `ID` = '%d' ",PlayerInfo[playerid][Spol],PlayerInfo[playerid][SQLID]);
            mysql_tquery(SQL,query);
            ShowPlayerDialog(playerid,DIALOG_DRZAVA,DIALOG_STYLE_LIST,"Drzava","Bih\nHrvatska\nSrbija\nCrna Gora\nMakedonija\nSlovenija\nOstalo","Unesi","Odustani");
         }
      }
      case DIALOG_DRZAVA:
      {
         if(!response)return Kick(playerid);
         if(response)
         {
            switch(listitem)
            {
               case 0:
               {
                  PlayerInfo[playerid][Drzava] = 0;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Bih!");
               }
               case 1:
               {
                  PlayerInfo[playerid][Drzava] = 1;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Hrvatska!");
               }
               case 2:
               {
                  PlayerInfo[playerid][Drzava] = 2;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Srbija!");
               }
               case 3:
               {
                  PlayerInfo[playerid][Drzava] = 3;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Crna Gora!");
               }
               case 4:
               {
                  PlayerInfo[playerid][Drzava] = 4;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Makedonije!");
               }
               case 5:
               {
                  PlayerInfo[playerid][Drzava] = 5;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Slovenija!");
               }
               case 6:
               {
                  PlayerInfo[playerid][Drzava] = 6;
                  SCM(playerid,COLOR_LIME,"Vi ste iz Ostalo!");
               }
            }
            new query[500];
            mysql_format(SQL,query,sizeof(query),"UPDATE `korisnici` SET `Drzava` = '%d' WHERE `ID` = '%d' ",PlayerInfo[playerid][Drzava],PlayerInfo[playerid][SQLID]);
            mysql_tquery(SQL,query);
            ShowPlayerDialog(playerid,DIALOG_GODINE,DIALOG_STYLE_INPUT,"Godine","Unesite vase godine!","Unesi","Odustani");
         }
      }
      case DIALOG_GODINE:
      {
         new god = strval(inputtext);
          if(god < 10)return ShowPlayerDialog(playerid, DIALOG_GODINE, DIALOG_STYLE_INPUT,"Unesite godine", "Godine ne mogu biti manje od 10 i vise od 65","Unesi", "Odustani");
          if(god > 65)return ShowPlayerDialog(playerid, DIALOG_GODINE, DIALOG_STYLE_INPUT,"Unesite godine", "Godine ne mogu biti manje od 10 i vise od 65","Unesi", "Odustani");
          PlayerInfo[playerid][Godine] = god;
          new query[500];
         mysql_format(SQL,query,sizeof(query),"UPDATE `korisnici` SET `Godine` = '%d' WHERE `ID` = '%d' ",PlayerInfo[playerid][Godine],PlayerInfo[playerid][SQLID]);
         mysql_tquery(SQL,query);
          SetSpawnInfo(playerid,0,PlayerInfo[playerid][Skin],0.0,0.0,0.0,0.0,0,0,0,0,0,0);
          SpawnPlayer(playerid);
          Ulogovan[playerid] = true;

      }
   }
   return 1;
}
forward insertSQLID(playerid);
public insertSQLID(playerid)
{
   PlayerInfo[playerid][SQLID] = cache_insert_id();
   printf("Kreiran nalog SQLID %d IME %s",PlayerInfo[playerid][SQLID],GetName(playerid));
   return 1;
}

forward SQL_Provjera(playerid);
public SQL_Provjera(playerid)
{
   switch(cache_num_rows())
   {
      case 0:
      {
         ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Registracija","Vasa lozinka moze biti samo manja 10 a ne duza od 65 ","Nasavi","Odustani");
      }
      case 1:
      {
         cache_get_value_name_int(0,"ID",PlayerInfo[playerid][SQLID]);
         cache_get_value_name(0,"Ime",PlayerInfo[playerid][Ime]);
         cache_get_value_name_int(0,"Lozinka",PlayerInfo[playerid][Lozinka]);
         cache_get_value_name_int(0,"Spol",PlayerInfo[playerid][Spol]);
         cache_get_value_name_int(0,"Drzava",PlayerInfo[playerid][Drzava]);
         cache_get_value_name_int(0,"Godine",PlayerInfo[playerid][Godine]);
         cache_get_value_name_int(0,"Novac",PlayerInfo[playerid][Novac]);
         cache_get_value_name_int(0,"Level",PlayerInfo[playerid][Level]);
         cache_get_value_name_int(0,"Respekti",PlayerInfo[playerid][Respekti]);
         cache_get_value_name_int(0,"Skin",PlayerInfo[playerid][Skin]);
         ShowPlayerDialog(playerid, DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Upisite svoju lozinku","Uloguj se","Odustani");
      }
   }
}

[/pawn]
Debug iz server_log(ukoliko je u pitanju crashanje servera - crashdetect log): [pawn]//[/pawn]
Slika/video ingame problema(obavezno ako je ingame problem): //
[pawn]Duplicate entry '0' for key 'PRIMARY'
Jel ti SQLID u bazi sa AUTO_INCREMENT ili ne[/pawn]
Poslednja Izmena: Jul 18, 2022, 15:47:28 POSLE PODNE od Jack_Ander


Citat: Bandit234 poslato Jul 18, 2022, 16:02:47 POSLE PODNE
Neznam kako da provjerim?
Ne znam *
Udji u bazu onda u tablicu igraci, i onda Structure i ides na SQLID edit i imas tamo pise AI i vidi je li ti stiklirano