MySQL's had enough? -
Lewwy - 18.07.2009
Hi there, I've recently downloaded an example script of MySQL.
Basically what this script does is save statistics to a player and stores them in an SQL' database.
Now, here's the main callback where I
THINK the error occurs;
pawn Код:
stock LoginPlayer(playerid,pass[])
{
new query[256],
result[256],
loop[256],
poop = 1;
MySQLCheck();
samp_mysql_real_escape_string(GetPlayerNameEx(playerid),GetPlayerNameEx(playerid));
samp_mysql_real_escape_string(pass,pass);
format(query,sizeof(query),"SELECT * FROM `users` WHERE Username = '%s' AND Password = md5('%s')",GetPlayerNameEx(playerid),pass);
samp_mysql_query(query);
samp_mysql_store_result();
samp_mysql_fetch_row(result);
if(samp_mysql_num_rows() == 1)
{
samp_mysql_strtok(loop, "|", result);
while(samp_mysql_strtok(loop, "|", ""))
{
if(poop == 3) AccountInfo[playerid][Points] = strval(loop);
if(poop == 4) AccountInfo[playerid][Kills] = strval(loop);
if(poop == 5) AccountInfo[playerid][Deaths] = strval(loop);
if(poop == 6) AccountInfo[playerid][Admin] = strval(loop);
if(poop == 7) AccountInfo[playerid][TimesQuit] = strval(loop);
poop += 1;
}
samp_mysql_free_result();
GivePlayerMoney(playerid, 1337);
LoggedIn[playerid] = 1;
SpawnPlayer(playerid);
return 1;
}
else
{
SendClientMessage(playerid,COLOR_GREY," Invalid password.");
Wrongattempt[playerid] += 1;
}
return 1;
}
(Sorry about the slight indentation screw up but, oh well). I cannot add more than 7, I try to add one more, when I connect to the server it just doesn't let me connect.
I can't see the problem, I'm fairly new to MySQL and I thought an example script was the way to go..
Any ideas how I could add more?
pawn Код:
if(poop == 8) AccountInfo[playerid][OneMoreRow] = strval(loop);
= rejected connection for everyone who attempts to connect.
Plus I'm not too bothered about array sizes right now, I don't know what MySQL array sizes are supposed to be so, yeah.
Re: MySQL's had enough? -
help! - 13.10.2009
When you add a new row in your script, you also have to add it in the same tables in the mysql database.
Re: MySQL's had enough? -
Extremo - 13.10.2009
Quote:
Originally Posted by jarrah
When you add a new row in your script, you also have to add it in the same tables in the mysql database.
|
Well, by reading the code you would know that if it doesn't fetch another row, it wont continue the while loop either, hence it will ignore the last poop. Anyway, I can't seem to figure a problem at the exact time but I am looking.
Alright, I just found the problem. Silly me.
Well, lets have a look:
pawn Код:
new
query[256],
result[256],
loop[256],
poop = 1;
Well, the result could be 1024 cells big. The query itself CAN be 512 cells big. So, I am guessing that it might exceed the cells of result. I can't tell for sure but I can guess, if it doesn't I can surely re-write this as of how I would of done it.
Anyway, try making results 1024 cells big. The query is not needed to be changed, rather to be made smaller, like 128 cells big, because I don't think a username, plus the 32 cells long string from md5 as well as your query are longer then 128 cells.
Re: MySQL's had enough? -
Lewwy - 16.10.2009
Cheers for that but by looking at the topic date, I don't really need this anymore.