Mysql Registration help
#1

I am currently working on a mysql registration system. I have everything working besides taking things out of the database such as score and money. I have money set to 100 in the database and score set to 9. When I go into the game it gives me 53 dollars and 52 score. Can anyone help me sort this out?

Here is the code I am using.
pawn Код:
case LOGIN_DIALOG:
        {
            new Query[300];
            format(Query,sizeof(Query),"SELECT * FROM `names` WHERE `Username` = '%s' AND `Password` = '%s'", Name(playerid), inputtext);
            mysql_query(Query);
            mysql_store_result();
            if(!mysql_num_rows())
            {
                SendClientMessage(playerid, red, "Your account isnt registered or your password is wrong!");
                LoginDialog(playerid);
            }
            else
            {
                new stats[2500];
                if(mysql_fetch_row_format(stats))
                {
                    mysql_fetch_field_row(pInfo[playerid][Money],"Money");
                    mysql_fetch_field_row(pInfo[playerid][Level],"Level");
                    mysql_fetch_field_row(pInfo[playerid][Score],"Score");
                    SetPlayerScore(playerid, pInfo[playerid][Score]);
                    GivePlayerMoney(playerid,pInfo[playerid][Money]);
                    print(pInfo[playerid][Money]);
                    print(pInfo[playerid][Score]);
                }
                pInfo[playerid][logged] = 1;
                SendClientMessage(playerid, green, "You have succesfully logged in!");
                printf("%s (%i) logged in with password %s", Name(playerid), playerid, inputtext);
            }
            mysql_free_result();
            if(response == 0)
            {
                SendClientMessage(playerid, red, "You must log in or register to use this server");
            }
            return 1;
         }
Reply
#2

Perhaps put it in a stock?
Reply
#3

You do not need a stock but when you get the Query string from the db and then split it with sscanf.

so instead of mysql_fetch_field_row(...) use sscanf(stats, "p<|>ddd", pInfo[playerid][Money], pInfo[playerid][Score], pInfo[playerid][Level]);
Reply
#4

Could this part of the sscanf be explained? "p<|>ddd" I read the sscanf post and I still have no idea how to use it on something like this.
Reply
#5

p<|> = split were it finds a | and d = a interger so a number
Reply
#6

So if i understand this rite. In my mysql_log this shows up: [16:54:43] CMySQLHandler::FetchRow() - Return: Futuretrucker|zack|255.255.255.255|100|9|5

I would use this code to get the values? : sscanf(stats, "p<|>sssddd", pInfo[playerid][Pname], pInfo[playerid][Password], pInfo[playerid][Ip], pInfo[playerid][Money], pInfo[playerid][Score], pInfo[playerid][Level]);
Reply
#7

Quote:
Originally Posted by futuretrucker
Посмотреть сообщение
So if i understand this rite. In my mysql_log this shows up: [16:54:43] CMySQLHandler::FetchRow() - Return: Futuretrucker|zack|255.255.255.255|100|9|5

I would use this code to get the values? : sscanf(stats, "p<|>sssddd", pInfo[playerid][Pname], pInfo[playerid][Password], pInfo[playerid][Ip], pInfo[playerid][Money], pInfo[playerid][Score], pInfo[playerid][Level]);
That is correct!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)