MySQL INSERT INTO/UPDATE.
#1

Hello guys. I'm trying to save my faction information.

PHP код:
CMD:createfaction(playerid,params[])
{
    if(
Player[playerid][Admin] < 4) return SendClientMessage(playeridCOLOR_GREY"You must be an adminstrator to use this command");
    
ShowPlayerDialog(playeridfactionnamedDIALOG_STYLE_INPUT"Faction Creation""Enter the faction name below""Next");
    return 
1;

Under Enumerators I have.
PHP код:
enum FactionData
{
    
ID,
    
factionname,
    
factiontype
};
new 
Faction[MAX_PLAYERS][FactionData]; 
PHP код:
enum
{
    
LoginDialog,
    
RegisterDialog,
    
factionnamed,
    
factiontyped,
    
}; 
Under OnDialogResponse I have.

PHP код:
case factionnamed:
        {
            new 
query[500];
            
mysql_format(mysql,query,sizeof(query), "INSERT INTO `faction` (`factionname`,`factiontype`) VALUES ('%e')",inputtext);
            
mysql_tquery(mysqlquery"""");
            
ShowPlayerDialog(playeridfactiontypedDIALOG_STYLE_LIST"FACTION CREATION""Type 0(Drugs)\nType 1(Weapons)""Choose","Cancel");
            if(
dialogid == factiontyped)
            {
                if(
response)
                {
                    switch(
listitem)
                    {
                        
//mysql_format(mysql,query,sizeof(query), "UPDATE `accounts` SET `Admin` = %d WHERE ID = %d LIMIT 1",  level, Player[target][ID]);
                        
case 0:
                        {
                            
mysql_format(mysqlquery,sizeof(query), "UPDATE `faction` SET `factiontype` = '0' WHERE ID = %d LIMIT 1"Faction[playerid][ID]);
                            
mysql_tquery(mysqlquery"""");
                        }
                        
                        case 
1:
                        {
                             
mysql_format(mysqlquery,sizeof(query), "UPDATE `faction` SET `factiontype` = '1' WHERE ID = %d LIMIT 1"Faction[playerid][ID]);
                            
mysql_tquery(mysqlquery"""");
                        }
                    }
                }
            }
        } 
For some reason my faction name/type doesn't save. What am I doing wrong?
Reply
#2

At the INSERT INTO mysql format, there is something wrong.

You did insert into factionname and factiontype, but you forgot to set a value for the faction type. Try this:
PHP код:
mysql_format(mysql,query,sizeof(query), "INSERT INTO `faction` (`factionname`,`factiontype`) VALUES ('%e', '%d')",inputtemysql_format(mysql,query,sizeof(query), "INSERT INTO `faction` (`factionname`,`factiontype`) VALUES ('%e', '%d')",inputtextfactiontype); 
Replace the "factiontype" at the end with your factiontype variable
Reply
#3

PHP код:
new query[500];
case 
factionnamed:
    {
        if(
response)
        {
            if(!
strlen(inputtext)) return SendClientMessage(playerid, -1Invalid name);
               
mysql_format(mysql,query,sizeof(query), "INSERT INTO `faction` (`factionname`) VALUES ('%e')",inputtext);
             
mysql_query(mysqlquery);
             
mysql_format(mysql,query,sizeof(query), "SELECT ID FROM `faction` WHERE factioname = '%e'",inputtext);
             
mysql_query(mysqlquery);
               
Faction[playerid][ID] = cache_get_field_content_int(0"ID");
             
ShowPlayerDialog(playeridfactiontypedDIALOG_STYLE_LIST"FACTION CREATION""Type 0(Drugs)\nType 1(Weapons)""Choose","Cancel");
        }
case 
factiontyped:
    {
         if(
response)
           {
             switch(
listitem)
               {
                   case 
0:
                 {
                      
mysql_format(mysqlquery,sizeof(query), "UPDATE `faction` SET `factiontype` = '0' WHERE ID = %d LIMIT 1"Faction[playerid][ID]);
                    
mysql_query(mysqlquery);
                   }
                case 
1:
                {
                       
mysql_format(mysqlquery,sizeof(query), "UPDATE `faction` SET `factiontype` = '1' WHERE ID = %d LIMIT 1"Faction[playerid][ID]);
                       
mysql_query(mysqlquery);
                  }
             }
          } 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)