MYSQL syntax error
#1

Solved!
Solution:

php strings require a single quote ( ' ) around them, else you'll end up with a syntax error.
Per-example: '%s'


Quote:
Originally Posted by SQL error log
[00:18:10] CMySQLHandler::Query(INSERT INTO `playerdatabase` (`SQLID`,`Name`,`IP`,`OnlineTime`,`Admin`,`Helper` ,`Character1SQLID`,`Character2SQLID`,`Character3SQ LID`,`Pass`,`Banned`,`BanID`,`ProbationBy`,`Probat ionReason`,`ProbationUntil`,`Level`) VALUES (0,Wade456,127.0.0.1,178,0,0,0,0,0,18EC91CB4FF5D4A 5E8849583FB2BB1149A8355FC42377786DEF8660E3D7B801FC F1F3A4467DA2BE97A716902D409D70470232E4E4C7F7CC0C8E 3C790AE88138F,0,-1,'Never',Never,0,0)) - An error has occured. (Error ID: 1064, 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 '.0.1,178,0,0,0,0,0,18EC91CB4FF5D4A5E8849583FB2BB1 149A8355FC42377786DEF8660E3D7B8' at line 1)
Код:
new formatedmessage[500];
format(Globalquery,sizeof(Globalquery),"INSERT INTO `playerdatabase` (`SQLID`,`Name`,`IP`,`OnlineTime`,`Admin`,");
strcat(Globalquery,"`Helper`,`Character1SQLID`,`Character2SQLID`,`Character3SQLID`,`Pass`,`Banned`,");
strcat(Globalquery,"`BanID`,`ProbationBy`,`ProbationReason`,`ProbationUntil`,`Level`)");
format(formatedmessage,sizeof(formatedmessage)," VALUES (%d,%s,%s,%d,%d,%d,%d,%d,%d,%s,%d,%d,'%s',%s,%d,%d)",TotalRegistrations++,PlayerInfo[playerid][AccountName],
PlayerInfo[playerid][IP],OnlineTime, PlayerInfo[playerid][Admin],PlayerInfo[playerid][Helper],PlayerInfo[playerid][CharacterName1],PlayerInfo[playerid][CharacterName2],
PlayerInfo[playerid][CharacterName3],hashed,PlayerInfo[playerid][Banned],-1,"Never","Never",0,0);
strcat(Globalquery,formatedmessage);
mysql_query(Globalquery);

Information:

MySQL plugin version: BlueG's 5.0
Samp server version: 0.3x - 0.3.5.0

No compile errors - No runtime errors from the console.
In other areas of the script using the INSERT function, the script runs fine. I look for the issue to be something related to php in the formatting, which I'm unfamiliar with.
Reply
#2

While it's not necessary for integer and float values to be wrapped in single quotes, it is necessary for strings. Some of them in your query are wrapped in single quotes, but some of them aren't and that's what causes the error. Try with this code:

pawn Код:
new formatedmessage[500];
format(Globalquery,sizeof(Globalquery),"INSERT INTO `playerdatabase` (`SQLID`,`Name`,`IP`,`OnlineTime`,`Admin`,");
strcat(Globalquery,"`Helper`,`Character1SQLID`,`Character2SQLID`,`Character3SQLID`,`Pass`,`Banned`,");
strcat(Globalquery,"`BanID`,`ProbationBy`,`ProbationReason`,`ProbationUntil`,`Level`)");
format(formatedmessage,sizeof(formatedmessage)," VALUES (%d,'%s','%s',%d,%d,%d,%d,%d,%d,'%s',%d,%d,'%s','%s',%d,%d)",TotalRegistrations++,PlayerInfo[playerid][AccountName],
PlayerInfo[playerid][IP],OnlineTime, PlayerInfo[playerid][Admin],PlayerInfo[playerid][Helper],PlayerInfo[playerid][CharacterName1],PlayerInfo[playerid][CharacterName2],
PlayerInfo[playerid][CharacterName3],hashed,PlayerInfo[playerid][Banned],-1,"Never","Never",0,0);
strcat(Globalquery,formatedmessage);
mysql_query(Globalquery);
I suggest you update your version of the plugin to R7 or newer, and start using threaded queries with cache.
Reply
#3

Alright, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)