SA-MP Forums Archive
I am getting this SQL error when I shouldn't be... - 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: I am getting this SQL error when I shouldn't be... (/showthread.php?tid=640320)



I am getting this SQL error when I shouldn't be... - adamslj - 01.09.2017

I am getting the following error...
Quote:

** [MySQL]: Unknown column 'carFaction' in 'field list'

when executing this command...

PHP код:
CMD:createfcar(playeridparams[])
{
    static
        
model[32],
        
color1,
        
color2,
        
factionid;
    if (
PlayerData[playerid][pAdmin] < 4)
        return 
SendErrorMessage(playerid"You don't have permission to use this command.");
    if (
sscanf(params"s[32]I(-1)I(-1)I(0)"modelcolor1color2factionid))
        return 
SendSyntaxMessage(playerid"/createfcar [modelid/name] [color1] [color2] [faction ID]");
    if ((
model[0] = GetVehicleModelByName(model)) == 0)
        return 
SendErrorMessage(playerid"Invalid model ID.");
    static
        
Float:x,
        
Float:y,
        
Float:z,
        
Float:angle,
        
id = -1;
    
GetPlayerPos(playeridxyz);
    
GetPlayerFacingAngle(playeridangle);
    
id FactionCar_Create(model[0], xy1anglecolor1color2factionidGetPlayerVirtualWorld(playerid));
    if (
id == -1)
        return 
SendErrorMessage(playerid"The server has reached the limit for dynamic vehicles.");
    return 
1;

As you can see, this command runs the query 'FactionCar_Create'
PHP код:
FactionCar_Create(modelidFloat:xFloat:yFloat:zFloat:anglecolor1color2factionworld)
{
    for (new 
0!= MAX_DYNAMIC_CARS++)
    {
        if (!
CarData[i][carExists])
           {
               if (
color1 == -1)
                   
color1 random(127);
            if (
color2 == -1)
                
color2 random(127);
               
CarData[i][carExists] = true;
            
CarData[i][carModel] = modelid;
            
CarData[i][carPos][0] = x;
            
CarData[i][carPos][1] = y;
            
CarData[i][carPos][2] = z;
            
CarData[i][carPos][3] = angle;
            
CarData[i][carColor1] = color1;
            
CarData[i][carColor2] = color2;
            new 
str[8], query[400];
            
format(strsizeof(str), "%s%s%d%d%s%s%s"LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], random(9), random(9), LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))]);
            
SetVehicleNumberPlate(istr);
            
format(CarData[i][carPlate], 11"%s"str);
            
CarData[i][carWorld] = world;
            
CarData[i][carFaction] = faction;
            
CarData[i][carVehicle] = CreateVehicle(modelidxyzanglecolor1color2, -1);
            if (
CarData[i][carVehicle] != INVALID_VEHICLE_ID) {
                
ResetVehicle(CarData[i][carVehicle]);
            }
            
mysql_format(g_iHandlequerysizeof(query), "INSERT INTO `factioncars` (carModel, carPosX, carPosY, carPosZ, carPosR, carColor1, carColor2, carPlate, carFaction, carWorld) VALUES(%d, %f, %f, %f, %f, %d, %d, '%s', %d, %d)",
                
CarData[i][carModel],
                
CarData[i][carPos][0],
                
CarData[i][carPos][1],
                
CarData[i][carPos][2],
                
CarData[i][carPos][3],
                
CarData[i][carColor1],
                
CarData[i][carColor2],
                
CarData[i][carPlate],
                
CarData[i][carFaction],
                
CarData[i][carWorld]
            );
            
mysql_tquery(g_iHandlequery"OnFactionCarCreated""i"i);
            return 
1;
        }
    }
    return -
1;
}
forward OnFactionCarCreated(carid);
public 
OnFactionCarCreated(carid)
{
    if (
carid == -|| !CarData[carid][carExists])
        return 
0;
    
CarData[carid][carID] = mysql_insert_id();
    
FactionCar_Save(carid);
    return 
1;
}
FactionCar_Save(carid)
{
    static
        
query[900];
    if (
CarData[carid][carVehicle] != INVALID_VEHICLE_ID)
    {
        for (new 
014++) {
            
CarData[carid][carMods][i] = GetVehicleComponentInSlot(CarData[carid][carVehicle], i);
        }
    }
    
format(querysizeof(query), "UPDATE `playercars` SET `carModel` = '%d', `carOwner` = '%d', `carPosX` = '%.4f', `carPosY` = '%.4f', `carPosZ` = '%.4f', `carPosR` = '%.4f', `carColor1` = '%d', `carColor2` = '%d', `carPlate` = '%s', `carFaction` = '%d', `carWorld` = '%d', `carRank` ='%d' WHERE `carID` = '%d'",
        
CarData[carid][carModel],
        
CarData[carid][carPos][0],
        
CarData[carid][carPos][1],
        
CarData[carid][carPos][2],
        
CarData[carid][carPos][3],
        
CarData[carid][carColor1],
        
CarData[carid][carColor2],
        
CarData[carid][carPlate],
        
CarData[carid][carFaction],
        
CarData[carid][carWorld],
        
CarData[carid][carRank],
        
CarData[carid][carID]
    );
    return 
mysql_function_query(g_iHandlequeryfalse"""");

This successfully creates the car and saves it to the database, including the 'carFaction' value. The tables look like this...


So... if it's creating the car and also saving the carFaction value, why am I getting this error? Everything is working as it should.


Re: I am getting this SQL error when I shouldn't be... - Vince - 01.09.2017

I see two different tables in your code above. So which one is the one you've shown?


Re: I am getting this SQL error when I shouldn't be... - adamslj - 01.09.2017

Quote:
Originally Posted by Vince
Посмотреть сообщение
I see two different tables in your code above. So which one is the one you've shown?
Oh oops..


Re: I am getting this SQL error when I shouldn't be... - LazzyBoy - 01.09.2017

You need row carFaction at `factioncars` table and also at `playercars`

check if both of tables has carFaction row or not


Re: I am getting this SQL error when I shouldn't be... - adamslj - 01.09.2017

Yeah I see the error now, FactionCar_Save is updating playercars when it should be updating factioncars, stupid mistake.