Saving age from dialog to SQLite
#1

Hey yall, im trying to save the age from an inputtext from an dialog.
I played around with it for around an hour or two but I cant get it to work.
I just want to store what ever number the player entered in dialogid 3 and save it to the SQLite database.

Code:

pawn Код:
public OnPlayerSpawn(playerid)
{  
        new str[2500];
    strcat(str,""chat" "COL_WHITE"Enter your age");
    ShowPlayerDialog(playerid,3,DIALOG_STYLE_INPUT,""COL_WHITE"Alice",str,"Enter","");
        return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{

     if(dialogid == 3)
     {
        if(response)
        {
            new Query[1000];
            new amount[128] = inputtext;
            User[playerid][USER_AGE] = amount[playerid];
            format(Query, sizeof(Query), "UPDATE users SET age = %d", User[playerid][USER_AGE]);
            db_query(Database, Query);

        }
     }
}
Reply
#2

PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
     if(
dialogid == 3)
     {
        if(
response)
        {
            new 
Query[1000];
            
User[playerid][USER_AGE] = strval(inputtext);
            
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]);
            
db_query(DatabaseQuery);
        }
    }

Reply
#3

Quote:
Originally Posted by Iszcegg
Посмотреть сообщение
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
     if(
dialogid == 3)
     {
        if(
response)
        {
            new 
Query[1000];
            
User[playerid][USER_AGE] = strval(inputtext);
            
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]);
            
db_query(DatabaseQuery);
        }
    }

Works! Thank you.
Reply
#4

PHP код:
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]); 
Will update every users's age to the current value, no?
Reply
#5

Quote:
Originally Posted by Voxel
Посмотреть сообщение
Works! Thank you.
Make sure you reduce Query[1000] down to the amount of characters you actually need there, it looks like you're using under 30 characters. You will reduce memory usage in your AMX by making sure you don't have such large strings.

Query[30] will be fine.

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
PHP код:
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]); 
Will update every users's age to the current value, no?
No. Read the code, the age variable is set BEFORE the query.
Reply
#6

Quote:
Originally Posted by Calgon
Посмотреть сообщение
No. Read the code, the age variable is set BEFORE the query.
Dayrion does not refer to variable. It WILL update the age of all users in the table unless WHERE clause is used to identify the user (by registration id or name).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)