not saving correctly [MYSQL]
#1

Well it's not saving correcly

PHP код:
                new query[1500];
                
mysql_real_escape_string(pInfo[playerid][Nick], pInfo[playerid][Nick]);
                
mysql_real_escape_string(pInfo[playerid][IP], pInfo[playerid][IP]);
                
format(querysizeof(query), "INSERT INTO `playerdata` (`nick`, `password`, `ip`, `age`, `gender`, `skin`, `email`, `score`, `money`) VALUES('%s', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d')",
                    
GetName(playerid),
                    
udb_hash(inputtext),
                    
pInfo[playerid][IP],
                    
pInfo[playerid][Age],
                    
pInfo[playerid][Gender],
                    
pInfo[playerid][Skin],
                    
pInfo[playerid][Email],
                    
StarterLevel,
                    
StarterMoney);
                
mysql_query(query);
            } 
Name, Password, Age, Gender, Skin, Level, Money is saving good, but IP and Email not...
Reply
#2

E-MAIL must not be integer, as we can see; email contains string.So make it string.( '%d' to '%s')
EDIT: String..I mean; varchar, of course!
Also, are you using this code when player disconnects?
Reply
#3

Quote:
Originally Posted by trablon
Посмотреть сообщение
E-MAIL must not be integer, as we can see; email contains string.So make it string.( '%d' to '%s')
EDIT: String..I mean; varchar, of course!
Also, are you using this code when player disconnects?
The disconnect
PHP код:
SavePlayer(playerid)
{
    if(
pInfo[playerid][Logged] == 1)
    {
        new 
Query[500];
        
format(Query500"UPDATE `playerdata` SET `age` = %d, `gender` = %d, `skin` = %d, `country` = %d, `email` = %d, `admin` = %d, `helper` = %d, `moderator` = %d, `score` = %d, `money` = %d, `gold` = %d, `kills` = %d, `deaths` = %d, `experiencepoints` = %d, `experiencepointsneeded` = %d, `kicks` = %d, `bans` = %d, `banned` = %d, `playinghours`= %d, `secondslogged` = %d, `adminhelp` = %d WHERE `id` = %d",
        
pInfo[playerid][Age],
        
pInfo[playerid][Gender],
        
pInfo[playerid][Skin],
        
pInfo[playerid][Country],
        
pInfo[playerid][Email],
        
pInfo[playerid][pAdmin],
        
pInfo[playerid][pHelper],
        
pInfo[playerid][pMod],
        
pInfo[playerid][pScore],
        
pInfo[playerid][pMoney],
        
pInfo[playerid][Gold],
        
pInfo[playerid][pKills],
        
pInfo[playerid][pDeaths],
        
pInfo[playerid][ExperiencePoints],
        
pInfo[playerid][ExperiencePointsNeeded],
        
pInfo[playerid][kicks],
        
pInfo[playerid][bans],
        
pInfo[playerid][pBanned],
        
pInfo[playerid][PlayingHours],
        
pInfo[playerid][SecondsLoggedIn],
        
pInfo[playerid][AdminHelp],
        
pInfo[playerid][ID]);
          
mysql_query(Query);
    }

Reply
#4

When you are going to use string in a MYSQL QUERY, you have to put ' twice('%s') and also you don't have to use it for integers.Just strings.

Correct one;

PHP код:
format(Query500"UPDATE `playerdata` SET `age` = %d, `gender` = %d, `skin` = %d, `country` = %d, `email` = '%s', `admin` = %d, `helper` = %d, `moderator` = %d, `score` = %d, `money` = %d, `gold` = %d, `kills` = %d, `deaths` = %d, `experiencepoints` = %d, `experiencepointsneeded` = %d, `kicks` = %d, `bans` = %d, `banned` = %d, `playinghours`= %d, `secondslogged` = %d, `adminhelp` = %d WHERE `id` = %d"
Reply
#5

Код:
`email` = %d
should be
Код:
`email` = '%s'
check other things. format strings with "%s" , integers with "%d" or "%i" and floats with "%f"

and a tip:

you don't need save every thing in "OnPlayerDisconnect" !

for example "age" , "gender" or admin and vip levels
save them into database when you set them them for a player.
Reply
#6

Neeeeermind, email and ip have %d when it should be %s
(I suggest you escape the email as well)
Reply
#7

@JaydenJason;
mysql_format, Allows you to format a string which you can safely use in a query.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)