SA-MP Forums Archive
Problem with MySQL Bank System - 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: Problem with MySQL Bank System (/showthread.php?tid=554599)



Problem with MySQL Bank System - FunnyBear - 04.01.2015

Hey,

I've been trying to script the base of a MySQL Bank System, and it doesn't seem to save the data.

I have 3 different functions,

pawn Код:
LoadBank(playerid)
{
    new
        name[ MAX_PLAYER_NAME ],
        query[ 300 ];
       
    GetPlayerName(playerid, name, sizeof(name));
    format(query, sizeof(query), "SELECT * FROM Bank WHERE Name='%s'", name);
    mysql_query(query);

    new String[ 40 ];
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(bInfo[playerid][bMoney],"bMoney");
        mysql_fetch_field_row(String,"AccID"); bInfo[playerid][AccID] = strval(String);
    }
    mysql_free_result();
}

SaveBank(playerid)
{
    new
        name[ MAX_PLAYER_NAME ],
        str[ 300 ];
       
    GetPlayerName(playerid, name, sizeof(name));
    format(str,sizeof(str),"UPDATE Bank SET bMoney=%d WHERE Name='%s'", bInfo[playerid][bMoney], name);
    mysql_query(str);
}

CreateBank(playerid)
{
    new
        name[ MAX_PLAYER_NAME ],
        query[ 300 ];

    GetPlayerName(playerid, name, sizeof(name));
    format(query, sizeof(query), "INSERT INTO Bank (Name, Money) VALUES('%s', 0)", name);
    mysql_query(query);
    mysql_free_result();
}
LoadBank, SaveBank, CreateBank.

So I have placed LoadBank under my MySQL login function, SaveBank on disconnect and CreateBank on mmy MySQL register function.

It doesn't seem to work. A new player has registered and their name wasn't saved to the table Banks

How am I able to fix this problem?

Thanks,

FunnyBear


Re: Problem with MySQL Bank System - BroZeus - 04.01.2015

Bank and Banks are two different tables make sure its the right one caz in description u writed that table name is Banks where as in code it is Bank


Re: Problem with MySQL Bank System - FunnyBear - 04.01.2015

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
Bank and Banks are two different tables make sure its the right one caz in description u writed that table name is Banks where as in code it is Bank
Yeah, sorry it was a typo. I meant to write Bank. The table name is the exact name in the script


Re: Problem with MySQL Bank System - BroZeus - 04.01.2015

put this in your OnGameModeInit -
mysql_log(1);
Now run the system then show us the mysql log file created in server directory


Re: Problem with MySQL Bank System - LivingLikeYouDo - 04.01.2015

Are you sure not using " ` " around 'Bank' will work? I never worked on MySQL queries without ` symbols around the name of the variable. Try using ` around it, like:
pawn Код:
"UPDATE `Bank` SET `bMoney`='%d' WHERE `Name`='%s'"



Re: Problem with MySQL Bank System - Dignity - 04.01.2015

Quote:
Originally Posted by LivingLikeYouDo
Посмотреть сообщение
Are you sure not using " ` " around 'Bank' will work?
Yes.


Re: Problem with MySQL Bank System - JonathanW - 04.01.2015

When I looked at the Avatar, the first thought that came to me was 'It's Vince? And He's asking something? Darn it.' XD


Re: Problem with MySQL Bank System - FunnyBear - 04.01.2015

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
put this in your OnGameModeInit -
mysql_log(1);
Now run the system then show us the mysql log file created in server directory
Thanks, I had commented mysql_debug before, and when I had removed the comment, I figured out the problem. On my CreateBank, I had Money, instead of bMoney. Silly me

Thanks