SA-MP Forums Archive
Error MySQL - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Error MySQL (/showthread.php?tid=511084)



Error MySQL - TheSy - 03.05.2014

I have this error with code:

pawn Код:
[21:52:11] CMySQLHandler::Query(INSERT INTO srp_players_weed SET ID=1, VW=0, Inte=0, planteur='Rislo_Blunt', PosX=1743.667480, PosY=-1857.371704, PosZ=13.414062, Variete=1, Temps=0, Grammes=0) - An error has occured. (Error ID: 1062, Duplicate entry '1' for key 'PRIMARY')
pawn Код:
if(listitem == 0)
                {
                    new sql[512], result[512], stringvariete[10];
                    new Interieur = GetPlayerInterior(playerid);
                    new VirtualWorld = GetPlayerVirtualWorld(playerid);
                    new idzeub = IDExistantWeed();
                    new Float:POX, Float:POY, Float:POZ;
                    GetPlayerPos(playerid, POX, POY, POZ);
                   
                    if(WeedInfo[idzeub][Variete] == 1) format(stringvariete, sizeof(stringvariete), "Amnйsia");
                   
                    WeedInfo[idzeub][ID] = idzeub;
                    WeedInfo[idzeub][VW] = VirtualWorld;
                    WeedInfo[idzeub][Inte] = Interieur;
                    strmid(WeedInfo[idzeub][Planteur], pName[playerid], 0, strlen(pName[playerid]), 255);
                    WeedInfo[idzeub][PosX] = POX;
                    WeedInfo[idzeub][PosY] = POY;
                    WeedInfo[idzeub][PosZ] = POZ;
                    WeedInfo[idzeub][Variete] = 1;
                    WeedInfo[idzeub][Temps] = 0;
                    WeedInfo[idzeub][Grammes] = 0;
                   
                    // objet + label
                   
                    format(sql, sizeof(sql), "SELECT COUNT(*) FROM srp_players_weed");
                    MySQLCheckConnection();
                    mysql_query(sql);
                    mysql_store_result();
                    mysql_fetch_row(result);
                    mysql_free_result();

                    format(sql, sizeof(sql), "INSERT INTO srp_players_weed SET ID=%d, VW=%d, Inte=%d, planteur='%s', PosX=%f, PosY=%f, PosZ=%f, Variete=%d, Temps=0, Grammes=0", idzeub, VirtualWorld, Interieur, pName[playerid], POX, POY, POZ, WeedInfo[idzeub][Variete]);
                    MySQLCheckConnection();
                    mysql_query(sql);
                }



Re: Error MySQL - PinEvil - 03.05.2014

Quote:
Originally Posted by thesy
(Error ID: 1062, Duplicate entry '1' for key 'PRIMARY')
Is this an error you encountered in-game? Or whilst compiling.


Re: Error MySQL - TheSy - 03.05.2014

In game and this error is in debug.txt!


Re: Error MySQL - Vince - 03.05.2014

Learn how to write proper queries, first. http://dev.mysql.com/doc/refman/5.1/en/insert.html
There is no SET anywhere in an INSERT query.


Re: Error MySQL - TheSy - 03.05.2014

All my other "requкtes" are working and this form ..


Re: Error MySQL - Vince - 03.05.2014

Uh, apparently it's valid syntax in MySQL after all. Just haven't seen anyone using it like that. It doesn't conform to standard SQL.

You should set the ID field in your table to auto increment. In the structure tab in phpMyAdmin click edit and tick the A_I checkbox for the ID field. Counting rows to find out the next id to insert is horrible.


Re: Error MySQL - TheSy - 03.05.2014

A loop would be better then?


Re: Error MySQL - TheSy - 04.05.2014

A loop would be better then?


Re: Error MySQL - TheSy - 04.05.2014

A loop would be better then?


Re: Error MySQL - iZN - 04.05.2014

Triple post won't help you. Vince already told you the solution.