PDA

View Full Version : [Help] Mysql query not working


tony_fitto
24/11/2012, 08:07 PM
Hey everyone,

I'm trying to count the rows here in my dealership, so you cant by more then 5 cars.
new car;
if(PlayerInfo[playerid][pLevel] < 2)
{
SendClientMessage(playerid, COLOR_GREY, "You need to be level 2 to buy a vehicle!");
return 1;
}
new sendername[MAX_PLAYER_NAME];
new DealershipString[900];
new Query3[9999], JaName[MAX_PLAYER_NAME], EscapedName[MAX_PLAYER_NAME];
GetPlayerName(playerid, JaName, sizeof(JaName));
new randMSG = random(sizeof(LicensePlate));
mysql_real_escape_string(JaName, EscapedName);
format(Query3, sizeof(Query3), "SELECT * FROM `vehicles` WHERE cOwner='%s'", EscapedName);
mysql_query(Query3);
mysql_store_result();
new OwnedCars = mysql_num_rows();
if(PlayerInfo[playerid][pDonateRank] != 5) {
if(OwnedCars == 0 || OwnedCars == 1 || OwnedCars == 2 || OwnedCars == 3 || OwnedCars == 4) { }
else return SendClientMessage(playerid, COLOR_GREY,"* You cant own more cars!");
} else {
if(OwnedCars == 0 || OwnedCars == 1 || OwnedCars == 2) { }
else return SendClientMessage(playerid, COLOR_GREY,"* You cant own more cars!");
}
mysql_free_result();
if(GetPlayerMoney(playerid) >= GetVehiclePrice(DealershipCar[playerid]))
{
if(PlayerInfo[playerid][pCarLic] == 1)
{
for(new h = MAX_OWNEDCARS; h < sizeof(CarInfo); h++)
{
if(CarInfo[h][cOwned] == 1)
{
car = h + 1;
}
}
CarInfo[car][cOwned] = 1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(CarInfo[car][cOwner], sendername, 0, strlen(sendername), 999);
new rand = 1 + random(2);
if(rand == 1) { CarInfo[car][cLocationx] = 942.7580; CarInfo[car][cLocationy] = -1439.3134; CarInfo[car][cLocationz] = 13.6766; CarInfo[car][cAngle] = 90.0000; }
else if(rand == 2) { CarInfo[car][cLocationx] = 942.7580; CarInfo[car][cLocationy] = -1426.3774; CarInfo[car][cLocationz] = 13.6766; CarInfo[car][cAngle] = 90.0000; }
else { CarInfo[car][cLocationx] = 942.7580; CarInfo[car][cLocationy] = -1426.3774; CarInfo[car][cLocationz] = 13.6766; CarInfo[car][cAngle] = 90.0000; }
SendClientMessage(playerid, COLOR_WHITE, "[INFO]: Your new vehicle spawned behind this dealership.");
GivePlayerMoney(playerid,-GetVehiclePrice(DealershipCar[playerid]));
CarInfo[car][cModel] = GetVehicleModel(DealershipCar[playerid]);
CarInfo[car][cVirWorld] = 0;
DestroyVehicle(car);
CreateVehicle(CarInfo[car][cModel],CarInfo[car][cLocationx],CarInfo[car][cLocationy],CarInfo[car][cLocationz],CarInfo[car][cAngle],1,1,30000);
PlayerPlayMusic(playerid);
format(DealershipString, sizeof(DealershipString), "Congratulations, you just bought a %s!", ArIsim[GetVehicleModel(DealershipCar[playerid])-400]);
SendClientMessage(playerid, COLOR_GRAD2, DealershipString);
DateProp(playerid);
OnPropUpdate();
OnPlayerUpdateEx(playerid);
DestroyVehicle(DealershipCar[playerid]);
PlayerTextDrawHide(playerid, Dealership0[playerid]);
PlayerTextDrawHide(playerid, Dealership1[playerid]);
PlayerTextDrawHide(playerid, Dealership2[playerid]);
PlayerTextDrawHide(playerid, Dealership4[playerid]);
PlayerTextDrawHide(playerid, Dealership5[playerid]);
PlayerTextDrawHide(playerid, Dealership6[playerid]);
PlayerTextDrawHide(playerid, Dealership7[playerid]);
CancelSelectTextDraw(playerid);
SetCameraBehindPlayer(playerid);
DealershipID[playerid] = 0;

format(Query3, sizeof(Query3), "INSERT INTO `vehicles` (cID, cLocationx, cLocationy, cLocationz, cAngle, cColorOne, cColorTwo, cOwner, cOwned, cLicense) VALUES('%d', '%f', '%f', '%f', '%f', '1', '1', '%s', '1', '%s%d')",
car,
CarInfo[car][cModel],
CarInfo[car][cLocationx],
CarInfo[car][cLocationy],
CarInfo[car][cLocationz],
CarInfo[car][cAngle],
EscapedName,
LicensePlate[randMSG],
car);
mysql_query(Query3);
}
else
{
SendClientMessage(playerid, COLOR_WHITE, "* For security reasons, a Driving License is needed to buy a car!");
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You don't have enough cash with you ! ");
return 1;
}

Thats what I've come up with but some how it's not working, I don't get a warning code, I dont get anything in game. When I removed the MySQL Query above when it's checking they keys I can by a car, but some how it doesn't spawn, it doesn't add it in to the database.

I'm so tired of this so it's unbelievable, and do I get any help here? No, I never do.
I'm getting so sick so if it's so hard to help me I'm even offering payment for this.

Unbelievable....

Peach
24/11/2012, 08:55 PM
One for a start you do not need a query this long: Query3[9999].

My suggestion is to look at your query and compare it with the one I have corrected for you. Cowner = 1 and COwned = the persons name, it should be the other way around.


format(Query3, sizeof(Query3), "INSERT INTO `vehicles` (cID ,cLocationx, cLocationy, cLocationz, cAngle, cColorOne, cColorTwo, cOwner, cOwned, cLicense) VALUES('%d', '%f', '%f', '%f', '%f', '1', '1', '%s', '1', '%d')",
car,
CarInfo[car][cLocationx],
CarInfo[car][cLocationy],
CarInfo[car][cLocationz],
CarInfo[car][cAngle],
EscapedName,
LicensePlate[randMSG]);


I noticed you forgot to save cModel inside this query so I removed it to keep things stable.

Vince
24/11/2012, 09:21 PM
SELECT count(*) FROM vehicles WHERE cOwner='%s'
Will return a single field with the amount of rows that match the criteria.

Also, what the hell is this weird construction?
if(OwnedCars == 0 || OwnedCars == 1 || OwnedCars == 2 || OwnedCars == 3 || OwnedCars == 4) { }


if(OwnedCars >= 5)
return SendClientMessage(playerid, COLOR_GREY,"* You cant own more cars!");

tony_fitto
24/11/2012, 11:14 PM
One for a start you do not need a query this long: Query3[9999].

My suggestion is to look at your query and compare it with the one I have corrected for you. Cowner = 1 and COwned = the persons name, it should be the other way around.


format(Query3, sizeof(Query3), "INSERT INTO `vehicles` (cID ,cLocationx, cLocationy, cLocationz, cAngle, cColorOne, cColorTwo, cOwner, cOwned, cLicense) VALUES('%d', '%f', '%f', '%f', '%f', '1', '1', '%s', '1', '%d')",
car,
CarInfo[car][cLocationx],
CarInfo[car][cLocationy],
CarInfo[car][cLocationz],
CarInfo[car][cAngle],
EscapedName,
LicensePlate[randMSG]);


I noticed you forgot to save cModel inside this query so I removed it to keep things stable.

Finaly some help, well I structured the query after the table, and now when you say it I missed the cModel, but still nothing is pust in the DB.

SELECT count(*) FROM vehicles WHERE cOwner='%s'
Will return a single field with the amount of rows that match the criteria.

Also, what the hell is this weird construction?
if(OwnedCars == 0 || OwnedCars == 1 || OwnedCars == 2 || OwnedCars == 3 || OwnedCars == 4) { }


if(OwnedCars >= 5)
return SendClientMessage(playerid, COLOR_GREY,"* You cant own more cars!");


Thank well, I just did it real fast on that part, you should only be able to have 5 cars as a premium member. but still thanks!

EDIT: I just tried everything of it, none of that did help. Car doesn't spawn. I don't even go past the count of all your cars.

new car;
if(PlayerInfo[playerid][pLevel] < 2)
{
SendClientMessage(playerid, COLOR_GREY, "You need to be level 2 to buy a vehicle!");
return 1;
}

if(PlayerInfo[playerid][pDonateRank] != 5)
{
SendClientMessage(playerid, COLOR_GREY, " [INFO] - This vehicle model is restricted for Premium 5 players only!");
return 1;
}
new sendername[MAX_PLAYER_NAME];
new DealershipString[900];
new Query3[9999], JaName[MAX_PLAYER_NAME], EscapedName[MAX_PLAYER_NAME];
GetPlayerName(playerid, JaName, sizeof(JaName));
mysql_real_escape_string(JaName, EscapedName);
format(Query3, sizeof(Query3), "SELECT count(*) FROM `vehicles` WHERE cOwner='%s'", EscapedName);
mysql_query(Query3);
new OwnedCars = mysql_num_rows();
if(OwnedCars <= 5) { }
else return SendClientMessage(playerid, COLOR_GREY,"* You cant own more cars!");
if(GetPlayerMoney(playerid) >= GetVehiclePrice(DealershipCar[playerid]))
{
if(PlayerInfo[playerid][pCarLic] == 1)
{
for(new h = MAX_OWNEDCARS; h < sizeof(CarInfo); h++)
{
if(CarInfo[h][cOwned] == 1)
{
car = h + 1;
}
}

CarInfo[car][cOwned] = 1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(CarInfo[car][cOwner], sendername, 0, strlen(sendername), 999);
new rand = 1 + random(2);
if(rand == 1) { CarInfo[car][cLocationx] = 942.7580; CarInfo[car][cLocationy] = -1439.3134; CarInfo[car][cLocationz] = 13.6766; CarInfo[car][cAngle] = 90.0000; }
else if(rand == 2) { CarInfo[car][cLocationx] = 942.7580; CarInfo[car][cLocationy] = -1426.3774; CarInfo[car][cLocationz] = 13.6766; CarInfo[car][cAngle] = 90.0000; }
else { CarInfo[car][cLocationx] = 942.7580; CarInfo[car][cLocationy] = -1426.3774; CarInfo[car][cLocationz] = 13.6766; CarInfo[car][cAngle] = 90.0000; }
SendClientMessage(playerid, COLOR_WHITE, "[INFO]: Your new vehicle spawned behind this dealership.");
GivePlayerMoney(playerid,-GetVehiclePrice(DealershipCar[playerid]));
CarInfo[car][cModel] = GetVehicleModel(DealershipCar[playerid]);
CarInfo[car][cVirWorld] = 0;
DestroyVehicle(car);
CreateVehicle(CarInfo[car][cModel],CarInfo[car][cLocationx],CarInfo[car][cLocationy],CarInfo[car][cLocationz],CarInfo[car][cAngle],1,1,30000);
PlayerPlayMusic(playerid);
format(DealershipString, sizeof(DealershipString), "Congratulations, you just bought a %s!", ArIsim[GetVehicleModel(DealershipCar[playerid])-400]);
SendClientMessage(playerid, COLOR_GRAD2, DealershipString);
DateProp(playerid);
OnPropUpdate();
OnPlayerUpdateEx(playerid);
DestroyVehicle(DealershipCar[playerid]);
PlayerTextDrawHide(playerid, Dealership0[playerid]);
PlayerTextDrawHide(playerid, Dealership1[playerid]);
PlayerTextDrawHide(playerid, Dealership2[playerid]);
PlayerTextDrawHide(playerid, Dealership4[playerid]);
PlayerTextDrawHide(playerid, Dealership5[playerid]);
PlayerTextDrawHide(playerid, Dealership6[playerid]);
PlayerTextDrawHide(playerid, Dealership7[playerid]);
CancelSelectTextDraw(playerid);
SetCameraBehindPlayer(playerid);
DealershipID[playerid] = 0;
new randMSG = random(sizeof(LicensePlate));
format(Query3, sizeof(Query3), "INSERT INTO `vehicles` (cID, cModel, cLocationx, cLocationy, cLocationz, cAngle, cColorOne, cColorTwo, cOwner, cOwned, cLicense) VALUES('%d', '%d', '%f', '%f', '%f', '%f', '1', '1', '%s', '1', '%s%d')",
car,
CarInfo[car][cModel],
CarInfo[car][cLocationx],
CarInfo[car][cLocationy],
CarInfo[car][cLocationz],
CarInfo[car][cAngle],
EscapedName,
LicensePlate[randMSG],
car);
mysql_query(Query3);
}
else
{
SendClientMessage(playerid, COLOR_WHITE, "* For security reasons, a Driving License is needed to buy a car!");
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You don't have enough cash with you ! ");
return 1;
}

tony_fitto
27/11/2012, 01:45 PM
Bump

tony_fitto
29/11/2012, 08:42 PM
bump bump