SA-MP Forums Archive
MYSQL errors - 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: MYSQL errors (/showthread.php?tid=422123)



MYSQL errors - MechaTech - 12.03.2013

I have two mysql errors and I can't find the mistake in it.

Код:
Error (0): Failed to exeute query. Column count doesn't match value count at row 1.
Error (0): Failed to exeute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''15.48225' at line 1.
Saving
pawn Код:
stock SavePlayer(playerid)
{
    new query[126], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    GetPlayerPos(playerid, PlayerS[playerid][Position][0], PlayerS[playerid][Position][1], PlayerS[playerid][Position][2]);
    format(query, sizeof(query), "UPDATE accounts SET Name = '%s', Password = '%s', PlayerX = '%f', PlayerY = '%f', PlayerZ = '%f' WHERE Name = '%s'", pName, PlayerS[playerid][Password], PlayerS[playerid][Position][0], PlayerS[playerid][Position][1], PlayerS[playerid][Position][2], pName);
    mysql_query(query);
}



Re: MYSQL errors - Misiur - 12.03.2013

pawn Код:
new query[126]
//to
new query[256]
Floats have 6 digits after dot, your query alone (including format specifiers) is 114 chars long


Re: MYSQL errors - MechaTech - 12.03.2013

Well one error is gone, but I still got one.
Код:
Error (0): Failed to exeute query. Column count doesn't match value count at row 1.



Re: MYSQL errors - Patrick - 12.03.2013

as i can see you forgot to put ; at the end. and you don't need to update/save player name and password that's kind off useless so try this code if it will work

pawn Код:
stock SavePlayer(playerid)
{
    new query[126], pName[24];
    GetPlayerName(playerid, pName, sizeof(pName));
    GetPlayerPos(playerid, PlayerS[playerid][Position][0], PlayerS[playerid][Position][1], PlayerS[playerid][Position][2]);
    format(query, sizeof(query), "UPDATE `accounts` SET `PlayerX` = '%f', `PlayerY` = '%f', `PlayerZ` = '%f' WHERE `Name` = '%s';", PlayerS[playerid][Position][0], PlayerS[playerid][Position][1], PlayerS[playerid][Position][2], pName);
    mysql_query(query);
}



Re: MYSQL errors - MechaTech - 13.03.2013

I just saw that the error is coming when I click Register.
There is something wrong in this code:
pawn Код:
new query[256], pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid, pName, sizeof(pName));
                format(query, sizeof(query), "INSERT INTO `accounts` VALUES ('%s', '%s')", pName, inputtext);
                mysql_query(query);

                SendClientMessage(playerid, -1, "Registered!");
                SetSpawnInfo(playerid, 1, 299, 1, 2, 3, 1, 1, 999, 1, 999, 1, 999);
                SpawnPlayer(playerid);



Re: MYSQL errors - CoaPsyFactor - 13.03.2013

LOL!, you are missing Columns you want to add INSERT INTO `accounts` (`Name`, `Password`) VALUES ('%s', '%s')


Re: MYSQL errors - Misiur - 13.03.2013

You can choose not to specify columns, but then you have to provide _all_ of them. So if there were id, name, password, then it'd be: "INSERT INTO `accounts` VALUES(null, '%s', '%s'). There is also insert set (like with update) syntax