Mysql Saving data problem
#1

Hello, everyone. I've been trying from a while to save the player data upon the player leaves the server, I've been trying to script it from a long time but I keep on getting error in one line ( marked it on the code provided below ). Can anyone help me out to resolve this issue and explain of where I went wrong? ( Plug version is R39-9 ).

PHP код:
    new Query[900];
    
GetPlayerName(playeridQueryMAX_PLAYER_NAME);
    
mysql_real_escape_string(QueryQuery);
    
format(Querysizeof(Query), "UPDATE `accounts` SET `Admin` = '%d', `VIP` = '%d', `Money` = '%d', `Kills` = '%d', `Deaths` = '%d', `Score` = '%d' WHERE `Name` = '%s'",
                                  
Player[playerid][Admin],
                                  
Player[playerid][VIP],
                                  
Player[playerid][Money],
                                  
Player[playerid][Kills],
                                  
Player[playerid][Deaths],
                                  
Player[playerid][Score],
                                  
Query);
    
mysql_query(Query);
    return 
1;

Reply
#2

900 cells for a name?

Use different variables for the name and the query itself, to avoid more confusion.
Reply
#3

You are storing the player's name in the Query array then again formatting the SQL query in the same array meaning the name is not stored there anymore. In your query in WHERE clause, you have specified the Query string as the player's name which was reformatted that's why the query could not access the table of the specified username.

As said above, use another variable for the name or the best way; use unique ids to execute the query to handle the player's table.

Plus, you don't need 900 cell of array for that query, 145 would be enough.

Edit: If you are using R39, why are you not using mysql_format? You can use %e specifier which escapes the string directly without having to use mysql_real_escape_string.
Reply
#4

I get the error on this line always, mysql_query(Query);
Reply
#5

This is what I tried right now but still it didn't save the data.
PHP код:
new query[150];
        new 
name[24];
        
        
GetPlayerName(playeridnameMAX_PLAYER_NAME);
        
mysql_real_escape_string(namename);
         
mysql_format(mysqlquerysizeof(query), "UPDATE 'accounts' `Admin` = '%d', `VIP` = '%d', `Money` = '%d', `Kills` = '%d', `Deaths` = '%d', `Score` = '%d' WHERE `Name` = '%s'",
                                  
Player[playerid][Admin],
                                  
Player[playerid][VIP],
                                  
Player[playerid][Money],
                                  
Player[playerid][Kills],
                                  
Player[playerid][Deaths],
                                  
Player[playerid][Score],
                                  
name);
    
mysql_query(mysqlquery); 
Help would be appreciated!
Reply
#6

Wrong quotes and you need the SET keyword, too. Somehow you manage to do it right the first time but not the second time. Because ... reasons?
Reply
#7

PHP код:
    new Query[900];
    
format(Querysizeof(Query), "UPDATE `accounts` SET `Admin` = '%d', `VIP` = '%d', `Money` = '%d', `Kills` = '%d', `Deaths` = '%d', `Score` = '%d' WHERE `Name` = '%e'",
                                  
Player[playerid][Admin],
                                  
Player[playerid][VIP],
                                  
Player[playerid][Money],
                                  
Player[playerid][Kills],
                                  
Player[playerid][Deaths],
                                  
Player[playerid][Score],
                                  
pname(playerid));
    
mysql_query(Query); // which is this line. 
This is my code but I still getting this error: C:\Users\MyPc\Desktop\Samp Server\gamemodes\Basic32.pwn(257) : error 035: argument type mismatch (argument 1)

Can't understand why it's giving an error.
Reply
#8

Quote:
Originally Posted by DeeadPool
Посмотреть сообщение
PHP код:
    new Query[900];
    
format(Querysizeof(Query), "UPDATE `accounts` SET `Admin` = '%d', `VIP` = '%d', `Money` = '%d', `Kills` = '%d', `Deaths` = '%d', `Score` = '%d' WHERE `Name` = '%e'",
                                  
Player[playerid][Admin],
                                  
Player[playerid][VIP],
                                  
Player[playerid][Money],
                                  
Player[playerid][Kills],
                                  
Player[playerid][Deaths],
                                  
Player[playerid][Score],
                                  
pname(playerid));
    
mysql_query(Query); // which is this line. 
This is my code but I still getting this error: C:\Users\MyPc\Desktop\Samp Server\gamemodes\Basic32.pwn(257) : error 035: argument type mismatch (argument 1)

Can't understand why it's giving an error.
Do you have created pName somewhere? Or you just add it because you saw in posts before?

Error is saying that there is a problem with line before, which means pName, there is not problem with function mysql_query();
Reply
#9

Quote:
Originally Posted by Sanady
Посмотреть сообщение
Do you have created pName somewhere? Or you just add it because you saw in posts before?
I've made my own stock for it which is:
PHP код:
stock pname(playerid)
{
    new 
GetName[24];
    
GetPlayerName(playeridGetName24);
    return 
GetName;

btw, I'm not copying scripts, I'm trying to learn MySQL by seeing the tutorials and understanding them.
Reply
#10

Quote:
Originally Posted by DeeadPool
Посмотреть сообщение
I've made my own stock for it which is:
PHP код:
stock pname(playerid)
{
    new 
GetName[24];
    
GetPlayerName(playeridGetName24);
    return 
GetName;

btw, I'm not copying scripts, I'm trying to learn MySQL by seeing the tutorials and understanding them.
Hmm, everything seems to be fine, do you have still the same error?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)