Error MySQL
#1

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);
                }
Reply
#2

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.
Reply
#3

In game and this error is in debug.txt!
Reply
#4

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.
Reply
#5

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

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

A loop would be better then?
Reply
#8

A loop would be better then?
Reply
#9

A loop would be better then?
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)