SA-MP Forums Archive
Mysql 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)
+--- Thread: Mysql Error: (/showthread.php?tid=451403)



Mysql Error: - Youice - 17.07.2013

Код:
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.374' at line 1.
What do that code mean?

code I assume you need to know:

pawn Код:
stock SavePlayerData(playerid)
{
    new query[128], pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
    PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
    GetPlayerPos(playerid, PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
    format(query, sizeof(query), "UPDATE accounts SET Name = '%s', Password = '%s', Money = '%d', PlayerX = '%f', PlayerY = '%f', PlayerZ = '%f' WHERE Name = '%s'",
                                                                                PlayerInfo[playerid][pName],
                                                                                PlayerInfo[playerid][pPw],
                                                                                PlayerInfo[playerid][pMoney],
                                                                                PlayerInfo[playerid][pPos_x],
                                                                                PlayerInfo[playerid][pPos_y],
                                                                                PlayerInfo[playerid][pPos_z],
                                                                                pname
                                                                                );
    mysql_query(query);
}



Re: Mysql Error: - gtakillerIV - 17.07.2013

''15.374' You're not closing the quotation. One quotation from the error and the 2nd one is yours.

Also, enclose your identifiers with a back tick ( ` ). Here's an example:

Код:
"UPDATE accounts SET Name = '%s',
Should be:

Код:
"UPDATE `accounts` SET `Name` = '%s',



Re: Mysql Error: - Youice - 17.07.2013

not working though


Re: Mysql Error: - [HiC]TheKiller - 17.07.2013

Try just using
pawn Код:
print(query);
I have a feeling that the query string is too small. You may want to increase that from 128.


Re: Mysql Error: - iJumbo - 17.07.2013

Код:
UPDATE accounts SET Name = 'LongUserName_asdasdsdfra', Password = 'AVerylongpasswordOrMD5?20381039812038120381029381029', Money = '100000', PlayerX = '10.00000', PlayerY = '10.00000', PlayerZ = '10.00000' WHERE Name = 'LongUserName_asdasdsdfra'
This is an example of your query.. the size with all informations is 244, 128 is too small


Edit: Pwned by [HiC]TheKiller .. too late XD


Re: Mysql Error: - SchurmanCQC - 17.07.2013

Quote:
Originally Posted by gtakillerIV
Посмотреть сообщение
''15.374' You're not closing the quotation. One quotation from the error and the 2nd one is yours.

Also, enclose your identifiers with a back tick ( ` ). Here's an example:

Код:
"UPDATE accounts SET Name = '%s',
Should be:

Код:
"UPDATE `accounts` SET `Name` = '%s',
Backticks are optional. I prefer to use them but they are not required by any means.


Re: Mysql Error: - Scenario - 17.07.2013

If you don't know how to use MySQL, then don't even try. Go read up on writing a proper MySQL query before you start coding a whole system.

You don't need apostrophe's around all non-string placeholders. Where you have '%d' it should be %d- the same goes for %f, %i, %x, etc. The only time you should surround a placeholder in an apostrophe is if it's a string (i.e. %s).


Re: Mysql Error: - SuperViper - 17.07.2013

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
If you don't know how to use MySQL, then don't even try. Go read up on writing a proper MySQL query before you start coding a whole system.

You don't need apostrophe's around all non-string placeholders. Where you have '%d' it should be %d- the same goes for %f, %i, %x, etc. The only time you should surround a placeholder in an apostrophe is if it's a string (i.e. %s).
Apostrophes around all placeholders is completely valid and makes code more organized, along with the wrapping of column names in `.


Re: Mysql Error: - Scenario - 17.07.2013

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Apostrophes around all placeholders is completely valid and makes code more organized, along with the wrapping of column names in `.
It's not, acually. Wrapping column and table names with a grave is fine, but using apostrophes for everything isn't a common practice and should be avoided unless you're dealing with strings.


Re: Mysql Error: - Youice - 17.07.2013

idk what's the problem goin' on here, but what I know that when I add new 3 columns, that error occurs in the debug.

error:
Код:
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.4' at line 1.
Код:
	PlayerX	float(7,4)	
        PlayerY	float(7,4)		
        PlayerZ	float(7,4)