SA-MP Forums Archive
Some Errors in my Stock - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Some Errors in my Stock (/showthread.php?tid=481400)



[MySQL] Get Free CarID Error - HellYeah - 15.12.2013

PHP код:
stock getFreeFraktAutoDBid()
{
    new 
pAuto,maxautos,data[256],query[256];
    
format(query,sizeof(query),"SELECT id FROM FraktionsCars ORDER by id DESC");
    
mysql_function_query(dbhandle,query,false,"","");
    
mysql_store_result();
    if(
mysql_num_rows()>0)
    {
        
data cache_get_field_content_int(0,"id",dbhandle);
        
//mysql_fetch_field("id",data);
        
maxautos=strval(data);
    }
    
mysql_free_result();
    for(new 
i=1i<=maxautos+1i++)
    {
        
format(query,sizeof(query),"SELECT id FROM FraktionsCars WHERE id='%i'",i);
        
mysql_function_query(dbhandle,query,false,"","");
        
mysql_store_result();
        if(
mysql_num_rows()==0)
        {
            
pAuto=i;
            return 
pAuto;
        }
    }
    return 
pAuto;

Errors:
PHP код:
C:\Users\asdasd\Desktop\SAMP Kunden\DevdogVideos\gamemodes\script.pwn(1890) : error 033: array must be indexed (variable "data"
(Im Trying to make a stock from mysql r7( (?) to r8(?) so there new natives)


Re: Some Errors in my Stock - Chenko - 15.12.2013

If this is the line that the error is on:

Код:
 data = cache_get_field_content_int(0,"id",dbhandle);
The problem is that data is a string and you are assigning it a value using a function that returns an integer.

Simply change these lines:

Код:
 data = cache_get_field_content_int(0,"id",dbhandle); 
 //mysql_fetch_field("id",data); 
 maxautos=strval(data);
To:

Код:
maxautos = cache_get_field_content_int(0,"id",dbhandle);
Although, I'm not sure that is exactly what you want to do as it will simply get the ID from the first row that the result returned.


AW: Re: Some Errors in my Stock - HellYeah - 15.12.2013

Quote:
Originally Posted by Chenko
Посмотреть сообщение
If this is the line that the error is on:

Код:
 data = cache_get_field_content_int(0,"id",dbhandle);
The problem is that data is a string and you are assigning it a value using a function that returns an integer.

Simply change these lines:

Код:
 data = cache_get_field_content_int(0,"id",dbhandle); 
 //mysql_fetch_field("id",data); 
 maxautos=strval(data);
To:

Код:
maxautos = cache_get_field_content_int(0,"id",dbhandle);
Although, I'm not sure that is exactly what you want to do as it will simply get the ID from the first row that the result returned.
Thanks but im becoming this error.
Код:
[17:45:02] [DEBUG] mysql_tquery - connection: 1, query: "SELECT id FROM FraktionsCars ORDER by id DESC", callback: "(null)", format: "(null)"
[17:45:02] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:45:02] [DEBUG] mysql_tquery - scheduling query "SELECT id FROM FraktionsCars ORDER by id DESC"..
[17:45:02] [DEBUG] cache_get_row_count - connection: 1
[17:45:02] [WARNING] cache_get_row_count - no active cache
[17:45:02] [DEBUG] mysql_tquery - connection: 1, query: "SELECT id FROM FraktionsCars WHERE id='1'", callback: "(null)", format: "(null)"
[17:45:02] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:45:02] [DEBUG] mysql_tquery - scheduling query "SELECT id FROM FraktionsCars WHERE id='1'"..
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[17:45:02] [DEBUG] cache_get_row_count - connection: 1
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:45:02] [WARNING] cache_get_row_count - no active cache
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:45:02] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO FraktionsCars (id,FraktionsID) VALUES ('1','5')", callback: "(null)", format: "(null)"
[17:45:02] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[17:45:02] [DEBUG] mysql_tquery - scheduling query "INSERT INTO FraktionsCars (id,FraktionsID) VALUES ('1','5')"..
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:45:02] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE FraktionsCars SET ModelID='411', CarX='180.695541', CarY=", callback: "(null)", format: "(null)"
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:45:02] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:45:02] [DEBUG] mysql_tquery - scheduling query "UPDATE FraktionsCars SET ModelID='411', CarX='180.695541', CarY='-66.606407', CarZ='2.293365', CarR='333.622283', CarDMG='1000.000000', Color1='3', Color2='3', Tank='30', Nitro='0', Abgeschleppt='0', Motorschaden='0', Kennzeichen='Medic', LastDriver='Niemand' WHERE id='1'"..
[17:45:02] [ERROR] CMySQLQuery::Execute[()] - (error #1062) Duplicate entry '1' for key 'PRIMARY'
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - error will be triggered in OnQueryError
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:45:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[17:45:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:45:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[17:45:02] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:45:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
PHP код:
ocmd:createfcar(playeridparams[])
{
    new 
Model,FraktionsID,Color1,Color2,Kennzeichen[24],string[128],query[400];
    if(!
IsPlayerAnAdmin(playerid,5))return SendClientMessage(playerid,COLOR_LIGHTRED,"Du bist kein Administrator!");
    if(
sscanf(params,"dddds[24]",Model,FraktionsID,Color1,Color2,Kennzeichen))return SendClientMessage(playerid,COLOR_LIGHTRED,"/createfcar [vehicleid] [fraktionsid] [color1] [color2] [kennzeichen]");
    if(
Model<400||Model>611)return SendClientMessage(playerid,COLOR_LIGHTRED,"Gьltige ModelID's sind 400-611");
    if(
FraktionsID>=25)return SendClientMessage(playerid,COLOR_LIGHTRED,"Diese Fraktion gibt es nicht!");
    new 
i=getFreeFraktAuto();
    new 
k=getFreeFraktAutoDBid();
    
format(query,sizeof(query),"INSERT INTO FraktionsCars (id,FraktionsID) VALUES ('%i','%d')",k,FraktionsID);
    
mysql_function_query(dbhandle,query,false,"","");
    new 
carid=k;
    new 
Float:cx,Float:cy,Float:cz,Float:cr;
    
GetPlayerPos(playerid,cx,cy,cz);
    
GetPlayerFacingAngle(playerid,cr);
    
FCar[i][fx]=cx;
    
FCar[i][fy]=cy;
    
FCar[i][fz]=cz;
    
FCar[i][fr]=cr;
    
FCar[i][fFraktionsID]=FraktionsID;
    
FCar[i][fColor1]=Color1;
    
FCar[i][fColor2]=Color2;
    
FCar[i][fTank]=30;
    
FCar[i][fdmg]=1000;
    
FCar[i][fNitro]=0;
    
FCar[i][fAbgeschleppt]=0;
    
FCar[i][fMotorschaden]=0;
    
FCar[i][fModelID]=Model;
    
format(FCar[i][fKennzeichen],24,"%s",Kennzeichen);
    
format(FCar[i][fLastDriver],24,"Niemand");
    
format(query,sizeof(query),"UPDATE FraktionsCars SET ModelID='%i', CarX='%f', CarY='%f', CarZ='%f', CarR='%f', CarDMG='%f', Color1='%d', Color2='%d', Tank='%d', Nitro='%i', Abgeschleppt='%i', Motorschaden='%i', Kennzeichen='%s', LastDriver='%s' WHERE id='%i'",
    
FCar[i][fModelID],FCar[i][fx],FCar[i][fy],FCar[i][fz],FCar[i][fr],FCar[i][fdmg],FCar[i][fColor1],FCar[i][fColor2],FCar[i][fTank],FCar[i][fNitro],FCar[i][fAbgeschleppt],FCar[i][fMotorschaden],FCar[i][fKennzeichen],FCar[i][fLastDriver],carid);
    
mysql_function_query(dbhandle,query,false,"","");
    
FCar[i][fDBID]=k;
    
FCar[i][fID] = CreateVehicle(Model,cx,cy,cz,cr,Color1,Color2,0);
    
SetVehicleNumberPlate(FCar[i][fID],FCar[i][fKennzeichen]);
    
PutPlayerInVehicle(playerid,FCar[i][fID],0);
    
format(string,sizeof(string),"** %s hat ein Fraktionsauto (ID: %d, FraktionsID: %d DbID: %d ) erstellt!",SpielerName(playerid),GetPlayerVehicleID(playerid),FCar[i][fFraktionsID],FCar[i][fDBID]);
    
SendAdminMessage(COLOR_YELLOW,string);
    
AdminLog(string);
    return 
1;
}
stock getFreeFraktAuto()
{
    new 
fAuto;
    for(new 
i=1i<MAX_FCARSi++)
    {
        if(
FCar[i][fID]==0&&FCar[i][fDBID]==0)
        {
            
fAuto=i;
            return 
fAuto;
        }
    }
    return 
fAuto;
}
stock getFreeFraktAutoDBid()
{
    new 
pAuto,maxautos,query[256];
    
format(query,sizeof(query),"SELECT id FROM FraktionsCars ORDER by id DESC");
    
mysql_function_query(dbhandle,query,false,"","");
    
mysql_store_result();
    if(
mysql_num_rows()>0)
    {
        
maxautos cache_get_field_content_int(0,"id",dbhandle);
    }
    
mysql_free_result();
    for(new 
i=1i<=maxautos+1i++)
    {
        
format(query,sizeof(query),"SELECT id FROM FraktionsCars WHERE id='%i'",i);
        
mysql_function_query(dbhandle,query,false,"","");
        
mysql_store_result();
        if(
mysql_num_rows()==0)
        {
            
pAuto=i;
            return 
pAuto;
        }
    }
    return 
pAuto;




Re: Some Errors in my Stock - Chenko - 15.12.2013

As far as I can tell that isn't an error, you simply have Mysql debug turned on so it's printing debug info whenever a function is used or it does something.


AW: Some Errors in my Stock - HellYeah - 15.12.2013

@Chenko:
PHP код:
[17:45:02] [ERRORCMySQLQuery::Execute[()] - (error #1062) Duplicate entry '1' for key 'PRIMARY' 



AW: Re: Some Errors in my Stock - HellYeah - 15.12.2013

Quote:
Originally Posted by Chenko
Посмотреть сообщение
As far as I can tell that isn't an error, you simply have Mysql debug turned on so it's printing debug info whenever a function is used or it does something.
PHP код:
[17:45:02] [ERRORCMySQLQuery::Execute[()] - (error #1062) Duplicate entry '1' for key 'PRIMARY' 



AW: Some Errors in my Stock - HellYeah - 15.12.2013

Why i cannot delete old posts -.-


Re: Some Errors in my Stock - Chenko - 16.12.2013

There is probably two rows in your Mysql database with the primary key 1 although I'm not positive. Try looking into your database and seeing if there is two, if there is delete one.


Re: Some Errors in my Stock - HellYeah - 16.12.2013

I looked there is none.


AW: Some Errors in my Stock - HellYeah - 17.12.2013

//Push