SA-MP Forums Archive
not saving correctly [MYSQL] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: not saving correctly [MYSQL] (/showthread.php?tid=582861)



not saving correctly [MYSQL] - lulo356 - 23.07.2015

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...


Re: not saving correctly [MYSQL] - trablon - 23.07.2015

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?


Re: not saving correctly [MYSQL] - lulo356 - 23.07.2015

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);
    }




Re: not saving correctly [MYSQL] - trablon - 23.07.2015

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"



Re: not saving correctly [MYSQL] - M4D - 23.07.2015

Код:
`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.


Re: not saving correctly [MYSQL] - JaydenJason - 23.07.2015

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


Re: not saving correctly [MYSQL] - trablon - 23.07.2015

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