MySQL INSERT INTO/UPDATE. -
DavidLuango - 30.07.2016
Hello guys. I'm trying to save my faction information.
PHP код:
CMD:createfaction(playerid,params[])
{
if(Player[playerid][Admin] < 4) return SendClientMessage(playerid, COLOR_GREY, "You must be an adminstrator to use this command");
ShowPlayerDialog(playerid, factionnamed, DIALOG_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(mysql, query, "", "");
ShowPlayerDialog(playerid, factiontyped, DIALOG_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(mysql, query,sizeof(query), "UPDATE `faction` SET `factiontype` = '0' WHERE ID = %d LIMIT 1", Faction[playerid][ID]);
mysql_tquery(mysql, query, "", "");
}
case 1:
{
mysql_format(mysql, query,sizeof(query), "UPDATE `faction` SET `factiontype` = '1' WHERE ID = %d LIMIT 1", Faction[playerid][ID]);
mysql_tquery(mysql, query, "", "");
}
}
}
}
}
For some reason my faction name/type doesn't save. What am I doing wrong?
Re: MySQL INSERT INTO/UPDATE. -
Ahmed21 - 30.07.2016
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')",inputtext, factiontype);
Replace the "factiontype" at the end with your factiontype variable
Re: MySQL INSERT INTO/UPDATE. -
Shinja - 30.07.2016
PHP код:
new query[500];
case factionnamed:
{
if(response)
{
if(!strlen(inputtext)) return SendClientMessage(playerid, -1, Invalid name);
mysql_format(mysql,query,sizeof(query), "INSERT INTO `faction` (`factionname`) VALUES ('%e')",inputtext);
mysql_query(mysql, query);
mysql_format(mysql,query,sizeof(query), "SELECT ID FROM `faction` WHERE factioname = '%e'",inputtext);
mysql_query(mysql, query);
Faction[playerid][ID] = cache_get_field_content_int(0, "ID");
ShowPlayerDialog(playerid, factiontyped, DIALOG_STYLE_LIST, "FACTION CREATION", "Type 0(Drugs)\nType 1(Weapons)", "Choose","Cancel");
}
case factiontyped:
{
if(response)
{
switch(listitem)
{
case 0:
{
mysql_format(mysql, query,sizeof(query), "UPDATE `faction` SET `factiontype` = '0' WHERE ID = %d LIMIT 1", Faction[playerid][ID]);
mysql_query(mysql, query);
}
case 1:
{
mysql_format(mysql, query,sizeof(query), "UPDATE `faction` SET `factiontype` = '1' WHERE ID = %d LIMIT 1", Faction[playerid][ID]);
mysql_query(mysql, query);
}
}
}