SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/03/2019, 09:09 PM   #1
OuDayas
Little Clucker
 
Join Date: Jan 2019
Posts: 49
Reputation: 0
Post MySQL didn't insert data

Hi, I'm trying to write a command for ban a player, technically only insert: username, the ban reason, name of admin, date and ip.

But when i insert the command in game, everything goes ok, but for the insert the data in the table don't work,
how can I fix that?

p.s: the part for if the target player is own player, I make like this in the comment for testing che cmd
My version of MySQL is r41 with zcmd, easydialog, foreach, sscanf and streamer
pawn Code:
CMD:ban(playerid, params[])
{   // admin lv: >=3 (moderatore)
    new TargetPlayer, banreason[128], str[128];
    if(Player[playerid][Admin] >= 3)
    {
        if(sscanf(params, "us[128]", TargetPlayer, banreason)) return SendClientMessage(playerid, COLOR_SYSTEM_ADMIN, "[COMANDO] Uso: /remoteban [Utente] [Motivo ban]");
        if(isvoid(banreason))
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Devi inserire il motivo del ban per: %s", Player[TargetPlayer][RPName]);
            SendClientMessage(playerid, -1, str);
            return 1;
        }/*
        if(TargetPlayer == playerid)
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Non puoi bannare te stesso!");
            SendClientMessage(playerid, -1, str);
            return 1;
        }*/

        if(!IsPlayerConnected(TargetPlayer))
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Giocatore non trovato{FFFF}, se registrato al server usa /remoteban");
            SendClientMessage(playerid, -1, str);
            return 1;
        }
        if(TargetPlayer != INVALID_PLAYER_ID)
        {
            // messaggio all'admin
            format(str, sizeof(str), "{FFFFFF}[INFO]: Hai appena bannato: {AFAFAFAF}%s", Player[TargetPlayer][RPName]);
            SendClientMessage(TargetPlayer, -1, str);
            format(str, sizeof(str), "{FFFFFF}[INFO]: Motivo: {FF0000}%s", banreason);
            SendClientMessage(TargetPlayer, -1, str);

            // messaggio all'utente bannato
            format(str, sizeof(str), "{FF0000}[BAN]: Sei Stato bannato da: {FFFF00}%s", Player[playerid][RPName]);
            SendClientMessage(TargetPlayer, -1, str);
            format(str, sizeof(str), "{FF0000}[BAN]: Motivo: {FFFF00}%s", banreason);
            SendClientMessage(TargetPlayer, -1, str);

            new banquery[256];
            mysql_format(g_SQL, banquery, sizeof banquery,
            "INSERT INTO 'bans' ('username', 'bannedby', 'reason', 'date', 'ip?) VALUES ('%e', '%e', '%e', '%e', '%e')",
            Player[TargetPlayer][Name], Player[playerid][Password], banreason, ReturnDate(), Player[TargetPlayer][LastIP]);
            mysql_tquery(g_SQL, banquery);
            DelayedKickTime(TargetPlayer, 1500); // 1,5 secondi
            return 1;
        }
    }
    else if(Player[playerid][Admin] < 3)
    {
        SendErrorMessage(playerid, ERROR_ADMIN_LEVEL);
        return 1;
    }
    else if(Player[playerid][Admin] == 0)
    {
        SendErrorMessage(playerid, ERROR_ADMIN);
        return 1;
    }
    return 1;
}
OuDayas is offline   Reply With Quote
Old 12/03/2019, 09:52 PM   #2
SymonClash
Huge Clucker
 
SymonClash's Avatar
 
Join Date: Dec 2018
Posts: 236
Reputation: 12
Default Re: MySQL didn't insert data

A parte che il comando è per il 50% sbagliato, mostra il mysql.log
SymonClash is offline   Reply With Quote
Old 12/03/2019, 09:59 PM   #3
L0K3D
Big Clucker
 
L0K3D's Avatar
 
Join Date: Apr 2015
Location: Republic of Moldova
Posts: 51
Reputation: 1
Default Re: MySQL didn't insert data

try this:
Code:
mysql_format(g_SQL, banquery, sizeof banquery,
            "INSERT INTO `bans` (`username`, `bannedby`, `reason`, `date`, `ip`) VALUES ('%e', '%e', '%e', '%e', '%e')",
            Player[TargetPlayer][Name], Player[playerid][Password], banreason, ReturnDate(), Player[TargetPlayer][LastIP]);
            mysql_tquery(g_SQL, banquery);
__________________
L0K3D is offline   Reply With Quote
Old 12/03/2019, 10:09 PM   #4
OuDayas
Little Clucker
 
Join Date: Jan 2019
Posts: 49
Reputation: 0
Default Re: MySQL didn't insert data

Oh i wrote the command wrong, sorry i didn't see that, this is the correct code. whit the code that L0K3D give me.
And the problem didn't fixed :\
(sorry for my bad English)
pawn Code:
CMD:ban(playerid, params[])
{   // admin lv: >=3 (moderatore)
    new TargetPlayer, banreason[128], str[128];
    if(Player[playerid][Admin] >= 3)
    {
        if(sscanf(params, "us[128]", TargetPlayer, banreason)) return SendClientMessage(playerid, COLOR_SYSTEM_ADMIN, "[COMANDO] Uso: /remoteban [Utente] [Motivo ban]");
        if(isvoid(banreason))
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Devi inserire il motivo del ban per: %s", Player[TargetPlayer][RPName]);
            SendClientMessage(playerid, -1, str);
            return 1;
        }/*
        if(TargetPlayer == playerid)
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Non puoi bannare te stesso!");
            SendClientMessage(playerid, -1, str);
            return 1;
        }*/

        if(!IsPlayerConnected(TargetPlayer))
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Giocatore non trovato{FFFF}, se registrato al server usa /remoteban");
            SendClientMessage(playerid, -1, str);
            return 1;
        }
        if(TargetPlayer != INVALID_PLAYER_ID)
        {
            // messaggio all'admin
            format(str, sizeof(str), "{FFFFFF}[INFO]: Hai appena bannato: {AFAFAF}%s", Player[TargetPlayer][RPName]);
            SendClientMessage(TargetPlayer, -1, str);
            format(str, sizeof(str), "{FFFFFF}[INFO]: Motivo: {FF0000}%s", banreason);
            SendClientMessage(TargetPlayer, -1, str);

            // messaggio all'utente bannato
            format(str, sizeof(str), "{FF0000}[BAN]: Sei Stato bannato da: {FFFF00}%s", Player[playerid][RPName]);
            SendClientMessage(TargetPlayer, -1, str);
            format(str, sizeof(str), "{FF0000}[BAN]: Motivo: {FFFF00}%s", banreason);
            SendClientMessage(TargetPlayer, -1, str);


//                     da qua non inserisce niente non so perché/ here don't insert nothing idk why                          
            new banquery[256];
            mysql_format(g_SQL, banquery, sizeof banquery,
            "INSERT INTO `bans` (`username`, `bannedby`, `reason`, `date`, `ip`) VALUES ('%s', '%s', '%s', '%s', '%s')",
            Player[TargetPlayer][Name], Player[TargetPlayer][RPName], banreason, ReturnDate(), Player[TargetPlayer][LastIP]);
            mysql_tquery(g_SQL, banquery);
            DelayedKickTime(TargetPlayer, 1500); // 1,5 secondi
            return 1;
        }
    }
    else if(Player[playerid][Admin] < 3)
    {
        SendErrorMessage(playerid, ERROR_ADMIN_LEVEL);
        return 1;
    }
    else if(Player[playerid][Admin] == 0)
    {
        SendErrorMessage(playerid, ERROR_ADMIN);
        return 1;
    }
    return 1;
}
OuDayas is offline   Reply With Quote
Old 12/03/2019, 10:14 PM   #5
SymonClash
Huge Clucker
 
SymonClash's Avatar
 
Join Date: Dec 2018
Posts: 236
Reputation: 12
Default Re: MySQL didn't insert data

Ma mostra il mysql log no?
SymonClash is offline   Reply With Quote
Old 12/03/2019, 10:43 PM   #6
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,855
Reputation: 3244
Default Re: MySQL didn't insert data

English only here please.
Y_Less is offline   Reply With Quote
Old 13/03/2019, 09:12 PM   #7
OuDayas
Little Clucker
 
Join Date: Jan 2019
Posts: 49
Reputation: 0
Default Re: MySQL didn't insert data

Guys I fixed...Its because the timer of 1.5 seconds, is too short, and I inserted a timer at 5 sec.
I have tryied that and work, this is the code.
pawn Code:
CMD:ban(playerid, params[])
{   // admin lv: >=3 (moderatore)
    new TargetPlayer, banreason[128], str[128], banquery[256];
    if(Player[playerid][Admin] >= 3)
    {
        if(sscanf(params, "us[128]", TargetPlayer, banreason)) return SendClientMessage(playerid, COLOR_SYSTEM_ADMIN, "[COMANDO] Uso: /remoteban [Utente] [Motivo ban]");
        if(isvoid(banreason))
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Devi inserire il motivo del ban per: %s", Player[TargetPlayer][RPName]);
            SendClientMessage(playerid, -1, str);
            return 1;
        }
        if(TargetPlayer == playerid)
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Non puoi bannare te stesso!");
            SendClientMessage(playerid, -1, str);
            return 1;
        }
        if(!IsPlayerConnected(TargetPlayer))
        {
            format(str, sizeof(str), "{FF0000}[ERRORE]: Giocatore non trovato{FFFFFF}, se registrato al server usa /remoteban");
            SendClientMessage(playerid, -1, str);
            return 1;
        }
        if(TargetPlayer != INVALID_PLAYER_ID)
        {   // messaggio all'admin
            format(str, sizeof(str), "{FFFFFF}[INFO]: Hai appena bannato: {AFAFAF}%s", Player[TargetPlayer][RPName]);
            SendClientMessage(TargetPlayer, -1, str);
            format(str, sizeof(str), "{FFFFFF}[INFO]: Motivo: {FF0000}%s", banreason);
            SendClientMessage(TargetPlayer, -1, str);
            // messaggio all'utente bannato
            format(str, sizeof(str), "{FF0000}[BAN]: Sei Stato bannato da: {FFFF00}%s", Player[playerid][RPName]);
            SendClientMessage(TargetPlayer, -1, str);
            format(str, sizeof(str), "{FF0000}[BAN]: Motivo: {FFFF00}%s", banreason);
            SendClientMessage(TargetPlayer, -1, str);

            mysql_format(g_SQL, banquery, sizeof(banquery),
            "INSERT INTO `bans` (`username`, `bannedby`, `banreason`, `date`, `ip`) VALUES ('%s', '%s', '%s', '%s', '%s')",
            Player[TargetPlayer][Name],
            Player[playerid][Name],
            banreason,
            ReturnDate(),
            Player[TargetPlayer][LastIP]);
            mysql_tquery(g_SQL, banquery);

            DelayedKickTime(TargetPlayer, 5000); // 1,5 secondi
            return 1;
        }
        return 1;
    }
    else if(Player[playerid][Admin] < 3)
    {
        SendErrorMessage(playerid, ERROR_ADMIN_LEVEL);
        return 1;
    }
    else if(Player[playerid][Admin] == 0)
    {
        SendErrorMessage(playerid, ERROR_ADMIN);
        return 1;
    }
    return 1;
}
OuDayas is offline   Reply With Quote
Old 15/03/2019, 12:37 AM   #8
Markski
Little Clucker
 
Join Date: Apr 2015
Location: La Plata, Argentina
Posts: 11
Reputation: 0
Default Re: MySQL didn't insert data

To be honest, if 1,5 seconds is not enough to run a simple INSERT query, you might have a more serious problem somewhere else, possibly in your database or in your MySQL plug-in. A query like that should take no more than a few milliseconds to run. Glad you found a solution, though.
__________________
Markski is offline   Reply With Quote
Old 15/03/2019, 09:10 AM   #9
SymonClash
Huge Clucker
 
SymonClash's Avatar
 
Join Date: Dec 2018
Posts: 236
Reputation: 12
Default Re: MySQL didn't insert data

Quote:
Originally Posted by Markski View Post
To be honest, if 1,5 seconds is not enough to run a simple INSERT query, you might have a more serious problem somewhere else, possibly in your database or in your MySQL plug-in. A query like that should take no more than a few milliseconds to run.
Exactly. Not more than 20-30 ms are required to run a simple INSERT query...
SymonClash is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert data with mysql OuDayas Scripting Help 5 26/01/2019 10:04 AM
mysql no insert data help.. BrnX Scripting Help 3 18/09/2017 05:01 PM
Mysql doesn't insert player data to database DuyDang2412 Scripting Help 7 28/02/2017 02:38 PM
Can't insert data into Database Tayab Scripting Help 2 31/01/2014 04:38 PM
MySQL how to insert data? PaulDinam Scripting Help 6 08/02/2013 09:54 AM


All times are GMT. The time now is 10:18 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.