• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] sqlite and inputtext
#1
I am trying to create an SQLite database, I only have three variables to keep it simple.



The problem is that the password is not saved unless I pass <inputtext> directly to the query.



Variables:



Code:
enum USER_DATA {

? ? USER_ID,

? ? USER_NICKNAME[MAX_PLAYER_NAME],

? ? USER_PASSWORD[20]

};



new gUserData[MAX_PLAYERS][USER_DATA];





Code working:





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

? ? switch (dialogid) {

? ? ? ? case DIALOG_REGISTRATION: {

? ? ? ? ? ? if (!response) return Kick(playerid);



? ? ? ? ? ? if (!(3 <= strlen(inputtext) <= 20)) {

? ? ? ? ? ? ? ? SendClientMessage(playerid, -1, "Tu contrase?a debe tener entre 3 y 20 car?cteres");

? ? ? ? ? ? ? ? ShowPlayerDialog(playerid, DIALOG_REGISTRATION, DIALOG_STYLE_PASSWORD, "Register", "Type in a password below to register an account.", "Register", "Leave" );

? ? ? ? ? ? ? ? return 1;

? ? ? ? ? ? }



? ? ? ? ? ? new query[208], DBResult: result;

? ? ? ? ? ?

? ? ? ? ? ? format(query, sizeof query, "INSERT INTO users (nickname, password) VALUES ('%q', '%s')", gUserData[playerid][USER_NICKNAME], inputtext);



? ? ? ? ? ? db_query(db_handle, query);



? ? ? ? ? ? SendClientMessage(playerid, 0x00FF00FF, "[SERVER]: You have just registered to our server! You have been automatically logged in!");



? ? ? ? ? ? result = db_query(db_handle, "SELECT last_insert_rowid()");

? ? ? ? ? ? gUserData[playerid][USER_ID] = db_get_field_int(result);



? ? ? ? ? ? db_free_result(result);

? ? ? ? }

? ? }

? ? return 1;

}



Code isn't working:



Code:
gUserData[playerid][USER_PASSWORD] = inputtext[strlen(inputtext)];? ? ? ? ? ?



? ? ? ? ? ? format(query, sizeof query, "INSERT INTO users (nickname, password) VALUES ('%q', '%s')", gUserData[playerid][USER_NICKNAME], gUserData[playerid][USER_PASSWORD]);



The password field on the database is empty, and other values are ok. No error has given from the compiler.
  Reply


Messages In This Thread
sqlite and inputtext - by robertocaribbean - 2021-03-21, 05:42 PM
RE: sqlite and inputtext - by Pinch - 2021-03-21, 05:45 PM
RE: sqlite and inputtext - by robertocaribbean - 2021-03-21, 06:37 PM
RE: sqlite and inputtext - by Bakr - 2021-03-21, 08:25 PM
RE: sqlite and inputtext - by robertocaribbean - 2021-03-21, 08:50 PM
RE: sqlite and inputtext - by Threshold - 2021-03-24, 04:46 AM
RE: sqlite and inputtext - by robertocaribbean - 2021-03-24, 02:14 PM

Forum Jump: