Sqlite Problem.
#1

Hey.I have a problem with my Sqlite System.
OnGameModeInit:
PHP код:
Database db_open("DataBase.db");
     
db_free_result(db_query(Database"CREATE TABLE IF NOT EXISTS `Conturi` (`PlayerIP`,\
                                                                               `Nume`,\
                                                                             `Parola`,\
                                                                             `AdminLevel`,\
                                                                             `Ucideri`,\
                                                                             `Decese`,\
                                                                                   `Bani`,\
                                                                               `Culoare`,\
                                                                             `Skin`,\
                                                                             `Level`)"
)); 
OnGameModeExit:
PHP код:
db_close(Database); 
OnPlayerConnect:
PHP код:
new Query[256], DBResult:Result;
    
format(Querysizeof(Query), "SELECT * FROM `Conturi` WHERE `Nume` = '%s'"DB_Escape(Name(playerid)));
    
Result db_query(Database,Query);
    new 
string[128];
    if(
db_num_rows(Result))
    {
    
format(string,sizeof(string),"{FFFFFF}Bine ai revenit {00FFFF}%s\nLast login {FF0000}XX:XX XX.XX.XX{FFFFFF}\nTe rog sa iti intoduci {FFFF00}parola",Name(playerid));
    
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Logare",string,"Logare","Iesire");
    }else{
    
format(string,sizeof(string),"{FFFFFF}Bine ai venit {00FFFF}%s{FFFFFF}.\n{FFFFFF}Te rog sa iti intoduci {FFFF00}parola {FFFFFF}pentru a te inregistra",Name(playerid));
    
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Inregisrtare",string,"Inregistrare","Iesire");
    }
    
db_free_result(DBResult:Result); 
and OnDialogResponde:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    new 
string[128],string2[128];
    switch( 
dialogid )
    {
        case 
DIALOG_REGISTER:
        {
                if(!
response) return Kick(playerid);
            if(
response)
            {
                
format(string,sizeof(string),"{FFFFFF}Bine ai venit {00FFFF}%s{FFFFFF}.\n{FF0000}In parola trebuie sa ai minim 4 caractere si maxim 26.",Name(playerid));
                if(
strlen(inputtext) < 4) return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Inregisrtare",string,"Inregistrare","Iesire");
                if(
strlen(inputtext) > 26) return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Inregisrtare",string,"Inregistrare","Iesire");
                {
                    
format(string2,sizeof(string2),"{FFFFFF}Bine ai venit {00FFFF}%s{FFFFFF}.\n{FF0000}Nu poti lasa campul gol.\n{FFFFFF}",Name(playerid));
                    if(!
strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Inregisrtare",string2,"Inregistrare","Iesire");
                    new 
name[MAX_PLAYER_NAME+1];
                    
GetPlayerName(playerid,name,sizeof(name));
                    new 
Query[129];
    
This is not work------>    format(Querysizeof(Query), "INSERT INTO `Conturi` (`PlayerIP`,`Nume`,\
                                                               `Parola`, `AdminLevel`,\
                                                               `Ucideri`,`Decese`,\
                                                               `Bani`,`Culoare`,\
                                                               `Skin`,`Level`) VALUES('%d','%s','%s','%d','%d','%d','%d','%d','%d','%d')"
,GetPlayerIPEx(playerid),DB_Escape(name),DB_Escape(inputtext),0,0,0,0,0,0,0);
            
                    
db_query(DatabaseQuery);
                    
db_free_resultdb_query(DatabaseQuery) );
                    
                    
                }
               }
        }
          case 
DIALOG_LOGIN:
        {
                if(!
response) return Kick(playerid);
            if(
response)
            {
            }
        }
    }
    return 
1;

Reply
#2

:bumb:
Reply
#3

I don't know at all how to use SQL through SAMP, but I think in SQL this is possible :

PHP код:
    format(Querysizeof(Query), "INSERT INTO `Conturi` (`PlayerIP`,`Nume`,\ 
                                                               `Parola`, `AdminLevel`,\ 
                                                               `Ucideri`,`Decese`,\ 
                                                               `Bani`,`Culoare`,\ 
                                                               `Skin`,`Level`) VALUES('%d','%s','%s','0','0','0','0','0','0','0')"
,GetPlayerIPEx(playerid),DB_Escape(name),DB_Escape(inputtext),0,0,0,0,0,0,0); 
And there's another way to proceed, but this one have to be done when you create your table :

PHP код:
CREATE TABLE IF NOT EXISTS `Conturi` (
            
PlayerIP VARCHAR(16NOT NULL,
            
Nume VARCHAR(25NOT NULL,
            
Parola VARCHAR(60NOT NULL,
            
AdminLevel SMALLINT NOT NULL DEFAULT 0,
            
Ucideri INT NOT NULL DEFAULT 0,
            
Decese INT NOT NULL DEFAULT 0,
            
Bani TINYINT NOT NULL DEFAULT 0,
            
Cloare INT NOT NULL DEFAULT 0,
            
Skin SMALLINT NOT NULL DEFAULT 0,
            
Level TINYINT NOT NULL DEFAULT 0,
            
Primary Key(whatever)
            )
    
ENGINE=INNODB
This way, you can just do (register step)

PHP код:

format
(querysizeof(query), "INSERT INTO Conturi (PlayerIP, Nume, Parola) VALUES ('%s', '%s', '%s')"GetPlayerIPEx(playerid), DB_Escape(name), DB_Escape(inputtext)); 
Oh and btw, it's strongly recommended to HASH (Whirlpool for example) your user passwords BEFORE inserting them in your database. Because once someone else than the user can see as plain text the passwords : they are leaked.
Reply


Forum Jump:


Users browsing this thread: