MySQL issues.
#1

Hey, I recently started working with mySQL, I have a problem with my login system.
It's just not loading the stats.

PHP код:
forward LoadUser(playerid);
public 
LoadUser(playerid)
{
new 
query[256];
format(querysizeof(query),"SELECT * FROM playerinfo WHERE Name=%s",pName(playerid));
mysql_query(query);
mysql_store_result();
if(
mysql_num_rows())
if(
mysql_fetch_row_format(query,"|"))
{
        new 
field[13][MAX_PLAYER_NAME];
        
explode(queryfield"|");
        
mysql_free_result();
        
PlayerInfo[playerid][Money] = strval(field[3]);
        
PlayerInfo[playerid][Admin] = strval(field[4]);
        
PlayerInfo[playerid][Level] = strval(field[5]);
        
PlayerInfo[playerid][Bank] = strval(field[6]);
        
PlayerInfo[playerid][Kills] = strval(field[7]);
        
PlayerInfo[playerid][Deaths] = strval(field[8]);
        
PlayerInfo[playerid][Skin] = strval(field[9]);
        
PlayerInfo[playerid][Job] = strval(field[10]);
        
PlayerInfo[playerid][Watch] = strval(field[11]);
        
PlayerInfo[playerid][Notepad] = strval(field[12]);
}

I can't find the problem.. can someone help me please?
Reply
#2

Quote:
Originally Posted by yanir3
Посмотреть сообщение
Hey, I recently started working with mySQL, I have a problem with my login system.
It's just not loading the stats.

pawn Код:
forward LoadUser(playerid);
public LoadUser(playerid)
{
new query[256];
format(query, sizeof(query),"SELECT * FROM playerinfo WHERE Name=%s",pName(playerid));
mysql_query(query);
mysql_store_result();
if(mysql_num_rows())
if(mysql_fetch_row_format(query,"|"))
{
        new field[13][MAX_PLAYER_NAME];
        explode(query, field, "|");
        mysql_free_result(); // This line must be under all other things you want to set
        PlayerInfo[playerid][Money] = strval(field[3]);
        PlayerInfo[playerid][Admin] = strval(field[4]);
        PlayerInfo[playerid][Level] = strval(field[5]);
        PlayerInfo[playerid][Bank] = strval(field[6]);
        PlayerInfo[playerid][Kills] = strval(field[7]);
        PlayerInfo[playerid][Deaths] = strval(field[8]);
        PlayerInfo[playerid][Skin] = strval(field[9]);
        PlayerInfo[playerid][Job] = strval(field[10]);
        PlayerInfo[playerid][Watch] = strval(field[11]);
        PlayerInfo[playerid][Notepad] = strval(field[12]);
}
}
I can't find the problem.. can someone help me please?
As you see above in the comment you free the result before you set anything put it under your last thing you want to get
Reply
#3

Tried using mysql_free_result in the end, still not workingn, I used explode to save the data.
Hmm, any other ideas to save the data?
Reply
#4

Quote:
Originally Posted by yanir3
Посмотреть сообщение
Tried using mysql_free_result in the end, still not workingn, I used explode to save the data.
Hmm, any other ideas to save the data?
which mysql plugin do you use ?
Reply
#5

g-stylez's one.
I use the same thing with my houses system and it works, can't figure out why this one isn't working.
Reply
#6

This is how it works for me
pawn Код:
// somewhere at the top of your script
#define mysql_fetch_row(%1) mysql_fetch_row_format(%1,"|")

if(mysql_num_rows () != 0)
{
    new line[300];
    if(mysql_fetch_row(line)) //Fetches the line
    {
           new data[13];//The data strings
           new data2[21]; //The data variables
           sscanf(line, "p<|>ds[24]s[60]ddddddddddddddddddd",data2[1], data[1],data[2],data2[2],data2[3],data2[4],data2[5],data2[6],data2[7],data2[8],data2[9],data2[10],data2[11],data2[12],data2[13],data2[14],data2[15],data2[16],data2[17],data2[18],data2[19],data2[20]); //Splits the line with sscanf
           SetPlayerScore(playerid, data2[3]); //Sets players score
           GivePlayerMoney(playerid,data2[2]); // Gives player money
           PlayerInfo[playerid][AdminLevel] = data2[4]; //Sets players admin level
    }
               
}
Reply
#7

Still not working, it's not even reaching the
Quote:

new data[13];//The data strings

part, I think it's stopping before the if(mysql_num_rows..
Reply
#8

Anyone?
Reply
#9

What is your code now that you've fixed the problem with mysql_free_result?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)