MySQL Syntax Error
#1

I am having trouble again, This time i cannot figure it out as this line is pretty much of long.

Код:
[07:37:25] CMySQLHandler::Query(VALUES('Sara_Washington', SHA1('ilovexenia'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, '192.168.1.100', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 'VALUES('Sara_Washington', SHA1('ilovexenia'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0,' at line 1)
I believe it is a missing "," but i have checked it ~ Can't seem to find anything wrong on the code.

PHP код:
MySQL_Register(playeridpasswordstring[])
{
    new 
query1[750], string[2000];
    
strcat(string"INSERT INTO `players` (`username`, `password`, `age`, `sex`, `skin`, `regsteps`, `level`, `cash`, `helper`, `tester`, `admin`, `donor`, `posx`, `posy`, `posz`, `posa`, `posvw`, `posint`, `IP`, `gun0`, `gun1`, `gun2`, `gun3`, `gun4`, `gun5`, `gun6`, `gun7`, `gun8`, `gun9`, `gun10`, `gun11`, `ammo0`, `ammo1`, `ammo2`, `ammo3`, `ammo3`, `ammo4`, `ammo5`, `ammo6`, `ammo7`, `ammo8`, `ammo9`, `ammo10`, `ammo11`) ");
    
format(query1750"VALUES('%s', SHA1('%s'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)"GetName(playerid), passwordstringpInfo[playerid][pIP]);
    
strcat(stringquery1);
    
mysql_query(query1);
    
    
pInfo[playerid][pSkin] = 0;
    
pInfo[playerid][pLevel] = 1;
    
pInfo[playerid][pRegisterSteps] = 1;
    
SendClientMessage(playerid, -1"You have been registered to International Roleplay (Saved in to our SQL database)");
    
SetSpawnInfo(playeridNO_TEAMpInfo[playerid][pSkin], pInfo[playerid][pPos][0], pInfo[playerid][pPos][1], pInfo[playerid][pPos][2], pInfo[playerid][pPos][3], 000000);
    
SpawnPlayer(playerid);
    
    
pInfo[playerid][pLogged] = 1;
    return 
1;

Reply
#2

You should really set all columns in which you want to store a 0 (as in your extremely long query) to have a default value of "0" using a tool that can browse your mysql tables (like Navicat).

That will shorten your query alot and you will find mistakes alot easier.

Your query could be reduced to:
PHP код:
format(query1160"INSERT INTO `players` (`username`, `password`, `IP`) VALUES('%s', SHA1('%s'), '%s')"GetName(playerid), passwordstringpInfo[playerid][pIP]); 
All other fields don't need to be inserted into your query if you set all those columns to default value of 0, because mysql will fill them in by itself if not supplied.
Note that the length of the query went from 750 to 160 (the maximim size of characters that would ever be inserted into the query: 24 chars for the name, 16 for the IP and 40 for the SHA1 hash).
That's about 1/5th the size of the original query, and does exactly the same thing when someone registers a new account.

Your actual problem was that you were mixing up both strings:
PHP код:
strcat(stringquery1);
mysql_query(query1); 
It should be:
PHP код:
strcat(stringquery1);
mysql_query(string); 
You were only sending the second part (starting from VALUES ...), instead of the merged query, which is stored into "string".
Reply
#3

Thank you ~ I learned something regardless to the null part.

Appreciated your help.
It worked.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)