what is wrong with create faction command
#1

Hello ,i create this command :
PHP Code:
CMD:fcreate(playeridparams[])
{
    new 
string[128], query[400], fname[32];
    if(
sscanf(params"s[32]"fname)) return SendClientMessage(playerid, -1"USAGE: /fcreate factionname");
    
// GETTING ALL THE FACTIONS CREATED, THEN ADDING 1 TO MAKE THE NEW ONE
    
Total_Factions_Created++;
    
//=====================================================================
    
    // THIS SETS THE FACTIONS NAME TO WHATEVER YOU JUST NAMED IT, PLUS SETS THE ID FOR THE FACTION
    
format(Factions[Total_Factions_Created][FactionName], 64"%s"fname);
    
Factions[Total_Factions_Created][ID] = Total_Factions_Created;
    
//==============================================================================================
    
    // THIS IS JUST TELLING YOU CREATED A FACTION, WITH THE NAME
    
format(stringsizeof(string), "You have created a faction named: %s(ID:%d).",Factions[Total_Factions_Created][FactionName], Factions[Total_Factions_Created][ID]);
    
SendClientMessage(playerid, -1string);
    
//================================================================================================
    
    // THIS IS SETTING ALL THE FACTION NAMES, WILL BE USED LATER FOR EDITTING AROUND
    
format(Factions[Total_Factions_Created][Rank1], 32"Rank 1 - Lowest");
    
format(Factions[Total_Factions_Created][Rank2], 32"Rank 2");
    
format(Factions[Total_Factions_Created][Rank3], 32"Rank 3");
    
format(Factions[Total_Factions_Created][Rank4], 32"Rank 4");
    
format(Factions[Total_Factions_Created][Rank5], 32"Rank 5");
    
//================================================================================
    
    // THIS IS FOR SAVING ALL THE DATA INTO THE MYSQL DATABASE
    
mysql_format(MySQL:Databasequerysizeof(query), "INSERT INTO 'factions' ('ID', 'FactionName', 'FactionLeader', 'Rank1name', 'Rank2name', 'Rank3name', 'Rank4name', 'Rank5name'"
        
Factions[Total_Factions_Created][ID],Factions[Total_Factions_Created][FactionName],Factions[Total_Factions_Created][FactionLeader],Factions[Total_Factions_Created][Rank1],
        
Factions[Total_Factions_Created][Rank2],Factions[Total_Factions_Created][Rank3],Factions[Total_Factions_Created][Rank4],Factions[Total_Factions_Created][Rank5]);
    
mysql_query(MySQL:Databasequery);
    
//=================================================================================
    
return 1;

But when i create a faction , my database is still blank...
Mysql: https://imgur.com/LFB0zJC.png
Reply
#2

I only looked at the query:
Code:
INSERT INTO 'factions' ('ID', 'FactionName', 'FactionLeader', 'Rank1name', 'Rank2name', 'Rank3name', 'Rank4name', 'Rank5name'
1- For table names, you either have to use no tips or backtips (``). So:
Code:
INSERT INTO factions
//or
INSERT INTO `factions`
Backtips are only required if it interferes with a MySQL keyword.

2- After using INSER INTO table_name you tell the query what columns a value should be inserted to, then you add the values:
Code:
INSERT INTO table_name (some_column, another_column, this_column) VALUES ('value_some_column', 'value_another_column', 'value_this_column');
If you insert data to all columns available
Code:
INSERT INTO table_name VALUES (...)
3- Check your mysql errors (SAMP_ROOT/logs/plugins/mysql.log) -You'll see there that the query failed.

I haven't looked at the rest of the script, more might be wrong. For now, focus on that query.
Reply
#3

I solve first problem
But i have a question ,i create 3 factions ,with 1, 2,3 ID .
If i delete faction with id 2 from database , and i create again another faction , new faction id is 4.
When i delete faction with id 2 ,and i create a new faction i want to be ID 2 , and next faction id 4 ...5...6
And if i make restart to server , and i try to create another faction . It start from 1 again. how i can solve this?
Reply
#4

Using AUTO_INCREMENT, the only way to do that (as far as I know) is by manually setting the ID after inserting a row.
If you want to start all over you'd have to clear the entire table
Code:
TRUNCATE factions;
This will delete all rows and also reset the AUTO_INCREMENT value.
Reply
#5

yea i use auto-increment.it's ok on database.
but i want see the corect id when i use command (in game).


EDIT: I delete all factions from database ,and now when i create a faction ,in game id is 1 and in database is 4 not 1....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)