Issue with MySQL (Data Insertion)
#1

Hey guys,

I recently picked SA:MP scripting back up out of boredom, so I decided to do a 100% scratch roleplay server; however I have ran into a small (but severe) issue. I have my MySQL database completely configured, however it's not letting me insert data via script. I have displayed the code below, I cannot figure it out, personally. It's connecting to the database, it's just not inserting data:

pawn Код:
public OnPlayerConnect(playerid)
{
    new playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
   
    new string[256];
    format(string,sizeof(string),"GET * FROM bans WHERE `pName` = '%s'", playerName);
    mysql_query(string);

    new result2[128];
    new result3[128];
    new String[128];

    mysql_retrieve_row();

    mysql_get_field("pName", result);
    mysql_get_field("pReasonBanned", result2);
    mysql_get_field("pBannedBy", result3);

    if(strval(result) == 1)
    {
        format(String, sizeof(String), "This account has been banned for the reason of: %s", result2);
        SendClientMessage(playerid, COLOR_RED, String);
        format(String, sizeof(String), "Your account was banned by administrator %s", result3);
        SendClientMessage(playerid, COLOR_RED, String);
        SendClientMessage(playerid, COLOR_RED, "This ban is permanent, you can appeal on our forums:");
        SendClientMessage(playerid, COLOR_RED, "http://www.countrylife-rp.comyr.com");
        Kick(playerid);
    }

    else if(strval(result) != 1)
    {
        new query[128];
        SendClientMessage(playerid, COLOR_RED, "You are not banned, for testing porposes, you have been banned");
        //format(String, sizeof(String), "INSERT INTO bans (pName, playerBannedBy, playerReasonBanned) VALUES('%s', 'JunkBuster', 'Test Ban')", playerName);
        format(String, sizeof(String), "INSERT INTO `bans` (`pName`) VALUES('%s')", playerName);
        mysql_query(query);
        print("Player banned for bug testing!");
    }
    return 1;
}
Any help will be appreciated (and +rep'ed if you actually explain my mistake to a degree where it'll be difficult for me to repeat the mistake)!

Thanks,
Nmader
Reply
#2

First it's SELECT not GET. As for the insertion, you're formatting the variable String with your query but you execute a blank query query.
Reply
#3

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
First it's SELECT not GET. As for the insertion, you're formatting the variable String with your query but you execute a blank query query.
I just fixed those two things, and I still receive this:
pawn Код:
MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec )
when I check phpMyAdmin, it's not inserting the data for some reason. :/
Reply
#4

Bump, does anyone have any idea why the data's not inserting with my new code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)