Insert data with mysql
#1

I have a little problem with a script that Im writing.
A login and register system RP, for a server, and I want make a system with the security questions, a list of questions with a free answer, but i don't know how I can make that, I found a little script. I tryied to copy but when show the dialog for selecting and writing the question after this didn't go forward the script and don't save the selection in the database.
Zip file (Is the mysql.wpn file)
but I don't understand how i can make the code, it's possible to create a list outside any public, with possibility to use in any type on dialogs?

this is the code of my script Pastebin link
Can someone help me?
(Sorry for my bad English Im from Italy )
Reply
#2

Can you paste the specific code and not the whole gamemode?
Reply
#3

Quote:
Originally Posted by Wanheda
View Post
Can you paste the specific code and not the whole gamemode?
Ok sorry...
Out of any public:
pawn Code:
#define MAX_SECURITY_QUESTION_SIZE 128
new const SECURITY_QUESTIONS[][MAX_SECURITY_QUESTION_SIZE] =
{
    "Domanda 1?",
    "Domanda 2?",
    "Domanda 3?"
};
And the interested dialogs
pawn Code:
case DIALOG_REGISTER_EMAIL:
        {
            if (!response)
            {
                Kick(playerid);
                return 1;
            }
            else
            {
                if (strlen(inputtext) <= 5) return ShowPlayerDialog(playerid, DIALOG_REGISTER_EMAIL, DIALOG_STYLE_INPUT, "Registrazione... [Step: 4/6]", "{FF0000}[ERRORE:]Devi inserire una mail valida\n{AFAFAF}Servirа per proteggere il tuo acount e cambiare domanda e/o risposta di sicurezza:", "Continua", "Annulla");
//                Player[playerid][PlayerEmail] = strlen(inputtext);
                format(Player[playerid][PlayerEmail], 128, inputtext);
                new query[221];
                mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`, `email`) VALUES ('%e', '%s', '%e', '%d', '%d', '%s')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex], Player[playerid][PlayerEmail]);
//              mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);

                new list[2 + (sizeof(SECURITY_QUESTIONS) * MAX_SECURITY_QUESTION_SIZE)];
                for (new i; i < sizeof(SECURITY_QUESTIONS); i++)
                {
                    strcat(list, SECURITY_QUESTIONS[i]);
                    strcat(list, "\n");
                }
                ShowPlayerDialog(playerid, DIALOG_REGISTER_DOMANDASEC, DIALOG_STYLE_LIST, "Registrazione - Domanda di sicurezza", list, "Continua", "Annulla");

            }
        }
        case DIALOG_REGISTER_DOMANDASEC:
        {
            if (!response)
            {
                Kick(playerid);
                return 1;
            }
            else
            {
                format(Player[playerid][e_USER_SECURITY_QUESTION], MAX_SECURITY_QUESTION_SIZE, SECURITY_QUESTIONS[listitem]);
//              format(Player[playerid][e_USER_SECURITY_QUESTION], 256, SECURITY_QUESTIONS[listitem]);
//              new query[221];
//              mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`, `email`, `domandasec`) VALUES ('%e', '%s', '%e', '%d', '%d', '%s', '%e')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex], Player[playerid][PlayerEmail], SECURITY_QUESTIONS[listitem]);
                new string[128];
                format(string, sizeof(string), "{AFAFAF}Hai selezionato come domanda di sicurezza:\n%s\n{FFFFFF}Inserisci una risposta di sicurezza", Player[playerid][e_USER_SECURITY_QUESTION]);
                ShowPlayerDialog(playerid, DIALOG_REGISTER_RISPOSTASEC, DIALOG_STYLE_INPUT, "Registrazione - Domanda di sicurezza [6/6]", string, "Continua", "Annuila");
//              mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
            }
        }
        case DIALOG_REGISTER_RISPOSTASEC:
        {
            if (!response)
            {
                Kick(playerid);
                return 1;
            }
            else
            {
                format(Player[playerid][e_USER_SECURITY_ANSWER], 128, inputtext);
                new query[221];
                mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`, `email`, `domandasec`, `rispostasec`) VALUES ('%e', '%s', '%e', '%d', '%d', '%s', '%e', '%s')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex], Player[playerid][PlayerEmail], Player[playerid][e_USER_SECURITY_QUESTION], strlen(inputtext));
                mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
            }
        }
but after the "DIALOG_REGISTER_RISPOSTASEC" dialog, the script is blocked, didn't send the player in the "OnPlayerRegister" query and didn't save datas in the database
Reply
#4

Quote:
Originally Posted by Y_Less
View Post
You are mixing %e, %d, and %s incorrectly. At at least one point you try format a string as a number.
I changed has a string, but didn't work, In the other script when goes to last 2 dialogs (the question and the answer) are sets %e and %s, here work, but with me no
Reply
#5

Place security questions after the player register. (In OnPlayerRegister callback). And you should escape strings with %e or even '%s'.

Also you're making a mess with dialogs.

%e - %s = strings.
%d = numbers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)