SA-MP Forums Archive
Mysql SavePlayer(playerid) error! - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Mysql SavePlayer(playerid) error! (/showthread.php?tid=252274)



Mysql SavePlayer(playerid) error! - Georgelopez1 - 30.04.2011

Hello,
I've been working on a Mysql login/register system today. Everything is working except for the SavePlayer stock.

Heres the enum:

pawn Код:
enum pInfo
{
    Username[25],
    Password[50],
    PlayerIP[19],
    Score[9]
}

new PlayerInfo[MAX_PLAYERS][pInfo];
Now here's the Stock:

pawn Код:
stock SaveUser(playerid)
{
    new Query[400]; format(Query, sizeof(Query), "UPDATE `names` (Username, Password, PlayerIP, Score) VALUES('%s', '%s', '%s', 's')", GetName(playerid), PlayerInfo[playerid][Password], GetIp(playerid), PlayerInfo[playerid][Score]);
    mysql_query(Query);
    print(Query);
}
And heres the Server_log.txt

Quote:

[12:55:35] [MySQL] 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 '(Username, Password, PlayerIP, Score) VALUES('Georgelopez1', '', '255.255.255.25' at line 1.
[12:55:35] UPDATE `names` (Username, Password, PlayerIP, Score) VALUES('Georgelopez1', '', '255.255.255.255', 's')
[12:55:35] [part] Georgelopez1 has left the server (0:1)

Thanks in advance.

P.S. I have changed the UPDATE to INSERT and still no results....

Oh and I'm using StrickenKids plugin.


Re: Mysql SavePlayer(playerid) error! - [L3th4l] - 30.04.2011

Your syntax is wrong. http://www.w3schools.com/php/php_mysql_update.asp


Re: Mysql SavePlayer(playerid) error! - Georgelopez1 - 30.04.2011

Could you tell me what is wrong? I have seen 3 different ways to do this, and each time I try its wrong.


Re: Mysql SavePlayer(playerid) error! - Retardedwolf - 30.04.2011

Код:
format(Query, sizeof(Query), "UPDATE `names` SET (Username, Password, PlayerIP, Score) VALUES('%s', '%s', '%s', '%d')", GetName(playerid), PlayerInfo[playerid][Password], GetIp(playerid), PlayerInfo[playerid][Score]);
EDIT: I didn't even check the score part, loled. ( I just copied off his code ) Edited.


Re: Mysql SavePlayer(playerid) error! - Zh3r0 - 30.04.2011

Since when score is a string? It's always numeric! Change it and set inside just %d at the Score column.


Re: Mysql SavePlayer(playerid) error! - Georgelopez1 - 30.04.2011

mysql_log
Quote:

[Sun May 1 15:57:40 2011] 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 '(Username, Password, PlayerIP, Score) VALUES('Georgelopez1', '', '255.255.255.25' at line 1.

Server_log
Quote:

[15:57:40] [MySQL] 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 '(Username, Password, PlayerIP, Score) VALUES('Georgelopez1', '', '255.255.255.25' at line 1.
[15:57:40] UPDATE `names` SET (Username, Password, PlayerIP, Score) VALUES('Georgelopez1', '', '255.255.255.255', '1')




Re: Mysql SavePlayer(playerid) error! - Georgelopez1 - 01.05.2011

Ok so heres my stock now:


pawn Код:
stock SaveUser(playerid)
{
    new Query[400];
    format(Query, sizeof(Query), "INSERT INTO `names` WHERE `Score` = %d",
    GetPlayerScore(playerid));
    mysql_query(Query);
    print(Query);
}
And here's the error:

Quote:

[09:01:43] [MySQL] 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 'WHERE `Score` = 10' at line 1.
[09:01:43] INSERT INTO `names` WHERE `Score` = 10
[09:01:43] [part] Georgelopez1 has left the server (0:1)




Re: Mysql SavePlayer(playerid) error! - Calgon - 01.05.2011

pawn Код:
stock SaveUser(playerid)
{
    new Query[400];
    format(Query, sizeof(Query), "UPDATE `names` SET `Username` = '%s', `Password` = '%s', `PlayerIP` = '%s', `Score` = '%d'", GetName(playerid), PlayerInfo[playerid][Password], GetIp(playerid), PlayerInfo[playerid][Score]);
    mysql_query(Query);
    print(Query);
}
Untested as I don't have windows installed to compile it.


Re: Mysql SavePlayer(playerid) error! - Kyle - 01.05.2011

Edit: Dont matter.