MySQL Issue
#1

Why does AccLock get a random value? Not really random, so far it got 110, 98 and 97.

This is how I save AccLock it is somewhere at the end.
Код:
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `Sex` = '%d', `Age` = '%d', `Pos_x` = '%f', `Pos_y` = '%f', `Pos_z` = '%f', `Skin` = '%d', `Job` = '%d', `AccLock` = '%d' WHERE `USERNAME` = '%e'"
		, PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pAccLock], pName);
	    mysql_tquery(Database, DB_Query);
This is the enum
Код:
enum pInfo
{
	ID,
    pPass[65],
    Salt[11],
    PasswordFails,
    Kills,
    Score,
    Deaths,
    pCash,
    pAdmin,
    pSex,
    pAge,
   	Float:pPos_x,
	Float:pPos_y,
	Float:pPos_z,
	pSkin,
	pTeam,
	pAccent,
	Cache: Player_Cache,
	LoggedIn,
	pEmail,
	pAccLock
}
This is how I load it:
Код:
cache_get_value_int(0, "AccLock", PlayerInfo[playerid][pAccLock]);
This checks if the account is locked:
Код:
if(PlayerInfo[playerid][pAccLock] == 1)
 	{
 	    new string[80];
 	    SendClientMessage(playerid, COLOR_GREEN, "SERVER: This account is locked, visit the forum to unlock it!");
 	    SendClientMessage(playerid, COLOR_GREEN, "> xxxxxxx");
 	    SetTimerEx("KickPlayer",500,false,"i",playerid);
 	    format(string, sizeof(string), "WARNING: %s tried to log into a locked account.", RPName(playerid));
		SendAdminMessage(COLOR_YELLOW, string);
		LockLog(string);
	}
Reply
#2

How are you setting it in the first place? Perhaps that's what is wrong, try to check your database manually and see if it saves appropriately or also saves a random value. Print the query as well and see what is the value in there, you need to find the root of this problem.
Reply
#3

People always blaming the problem on MySQL while its rarely got anything to do with it. I suppose pEmail stores text? Yet you haven't declared it as an array. Since pAccLock is right after it you will overwrite that value when you store the email. It's not a coincidence that you get those "random" values because these are the characters for the letters H, b and a, respectively.

And oh, don't use the name to query once you've retrieved the ID.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
People always blaming the problem on MySQL while its rarely got anything to do with it. I suppose pEmail stores text? Yet you haven't declared it as an array. Since pAccLock is right after it you will overwrite that value when you store the email. It's not a coincidence that you get those "random" values because these are the characters for the letters H, b and a, respectively.

And oh, don't use the name to query once you've retrieved the ID.
Yes, email stores text and in phpmyadmin it is set to VARCHAR and acclock is set to int but I don't understand how can those two conflict?




EDIT#

I just noticed that I didn't add a length for email in enum

email[64],

that was the issue..
Reply
#5

Код:
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `Sex` = '%d', `Age` = '%d', `Pos_x` = '%f', `Pos_y` = '%f', `Pos_z` = '%f', `Skin` = '%d', `Job` = '%d', `AccLock` = '%d' WHERE `USERNAME` = '%e'"
On an off topic note, you don't need to escape player names like you did here. It's unnecessary.
Reply
#6

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
Код:
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `Sex` = '%d', `Age` = '%d', `Pos_x` = '%f', `Pos_y` = '%f', `Pos_z` = '%f', `Skin` = '%d', `Job` = '%d', `AccLock` = '%d' WHERE `USERNAME` = '%e'"
On an off topic note, you don't need to escape player names like you did here. It's unnecessary.
I did it just to make sure, does it affect the gamemode in any way?
Reply
#7

Andrei and his issues xD
Reply
#8

Check this

OnGameModeInit

OnPlayerConnect

Query = Select * from user Where Username = %e okay
mysql_tquery Check_Account

okay

PHP код:
forward Check_Account(playerid);
public 
Check_Account(playerid)
{
         if(
cache_num_rows() > 0)
    {
                 
cache_get_value_name_int(0"AccLock"PlayerInfo[playerid][pAccLock]);
                 
Check_Ban(playerid);
        }
        else
        {
          
Register dialogs
        
}
        return 
1;

This is a example

PHP код:
forward Check_Ban(playerid);
public 
Check_Ban(playerid)
{
     if(
PlayerInfo[playerid][pAccLock] == 1)
     {
         new 
string[80];
         
SendClientMessage(playeridCOLOR_GREEN"SERVER: This account is locked, visit the forum to unlock it!");
         
SendClientMessage(playeridCOLOR_GREEN"> xxxxxxx");
          
SetTimerEx("KickPlayer",500,false,"i",playerid);
         
format(stringsizeof(string), "WARNING: %s tried to log into a locked account."RPName(playerid));
            
SendAdminMessage(COLOR_YELLOWstring);
            
LockLog(string);
   
    }
        else
        {
            
Login Dialog
        
}
     return 
1;

Reply
#9

I'm very surprised that no one has mentioned the fact your treating int like strings in MySQL.

You only need to put '' around data that is of a string type:

'%d' - Invalid Type ( should be %d without '' )
'%f' - Invalid Type ( this is a float not a string ).
'%e' - Valid Type ( since the escaped string is outputted )
'%s' - Valid Type ( since its a string )

I also hope that not every column in your table structure is a string, as this is really bad practice and will slow down your query.
Reply
#10

Quote:
Originally Posted by azzerking
Посмотреть сообщение
I'm very surprised that no one has mentioned the fact your treating int like strings in MySQL.

You only need to put '' around data that is of a string type:

'%d' - Invalid Type ( should be %d without '' )
'%f' - Invalid Type ( this is a float not a string ).
'%e' - Valid Type ( since the escaped string is outputted )
'%s' - Valid Type ( since its a string )

I also hope that not every column in your table structure is a string, as this is really bad practice and will slow down your query.
Oh, thanks for pointing this out for me, things like this help me improve my skills, from now on I will pay more attention, also the table is made right, I hope, I set INT for numbers, VARCHAR for text and FLOAT for float.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)