MySQL mysql_insert_id issues.
#1

Hello,
I'm having some issues with MySQL. I've made a command which makes a house and inserts it into a MySQL table. However, it doesn't save properly and only saves by the default values set in the database. When the update command is ran, it works perfect, except from it updates a blank ID.

Код:
[14:51:03] OnQueryFinish(1,"UPDATE samp_houses SET Owner = 'Nobody', Level = '0', Door = '0', Locked = '0', Alarm_Level = '0', Door_Level = '0', Rent_Enabled = '0', Rent_Fee = '0', Price = '0', Ext_Custom = '0', Ext_VW = '0', Ext_Int = '0', Ext_PosX = '367.834411', Ext_PosY = '2477.468017', Ext_PosZ = '19.413625', Ext_PosA = '210.444885', Int_Custom = '0', Int_VW = '0', Int_Int = '0', Int_PosX = '367.834411', Int_PosY = '2477.468017', Int_PosZ = '19.413625', Int_PosA = '210.444885', Obj_1 = '', Obj_2 = '', Obj_3 = '', Obj_4 = '', Obj_5 = '', Ward_1 = '0', Ward_2 = '0', Ward_3 = '0', Ward_4 = '0', Safe_Level = '0', Safe_Code = '0', Safe_PosX = '0.000000', Safe_PosY = '0.000000', Safe_PosZ = '0.000000', Safe_PosR = '0.000000', Safe_Money = '0', Safe_Syringes = '0', Safe_Zopiclone = '0', Safe_FatBurn = '0', Safe_DrugRemoval = '0', Safe_Crates = '0', Safe_Cocaine = '0', Safe_Meth = '0', Safe_Heroin = '0', Safe_Weed = '0', Safe_Weed_Seeds = '0', Safe_Wep_1 = '', Safe_Wep_2 = '0', Safe_Wep_3 = '0', Safe_Wep_4 = '0', Safe_Wep_5 = '0' WHERE ID = ''") - Called.
Pay attention to the last part where it says " WHERE ID = ''" "

I'd like to point out that the save feature isn't the problem, and that it's the "mysql_insert_id" features problem.

Here's where the problem lies:

Код:
COMMAND:createhouse(playerid) {
    if(PlayerInfo[playerid][pALevel] >= 4) {
        new string[128], labelString[96], ;

		mysql_query("INSERT INTO samp_houses (Owner) VALUES('Nobody')", g_MySQLConnections[0]);
  		houseid = mysql_insert_id();
		
		format(HouseVar[houseid][hOwner], MAX_PLAYER_NAME, "Nobody");
   	 	HouseVar[houseid][hExt_VW] = GetPlayerVirtualWorld(playerid);
		HouseVar[houseid][hExt_Int] = GetPlayerInterior(playerid);
		GetPlayerPos(playerid, HouseVar[houseid][hExt_PosX], HouseVar[houseid][hExt_PosY], HouseVar[houseid][hExt_PosZ]);
		GetPlayerFacingAngle(playerid, HouseVar[houseid][hExt_PosA]);
   	 	HouseVar[houseid][hInt_VW] = GetPlayerVirtualWorld(playerid);
		HouseVar[houseid][hInt_Int] = GetPlayerInterior(playerid);
		GetPlayerPos(playerid, HouseVar[houseid][hInt_PosX], HouseVar[houseid][hInt_PosY], HouseVar[houseid][hInt_PosZ]);
		GetPlayerFacingAngle(playerid, HouseVar[houseid][hInt_PosA]);
		
	 	format(labelString, sizeof(labelString), "House Number %d\nPrice: $%d", houseid, HouseVar[houseid][hPrice]);

		HouseVar[houseid][hLabelID] = CreateDynamic3DTextLabel(labelString, COLOR_YELLOW, HouseVar[houseid][hExt_PosX], HouseVar[houseid][hExt_PosY], HouseVar[houseid][hExt_PosZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
		HouseVar[houseid][hPickupID] = CreateDynamicPickup(1273, 23, HouseVar[houseid][hExt_PosX], HouseVar[houseid][hExt_PosY], HouseVar[houseid][hExt_PosZ], 0, HouseVar[houseid][hExt_VW], -1, 250);
  		SaveHouse(houseid);
  		SystemStats[HouseCount]++;
		format(string, sizeof(string), "You've created a house, under an ID: %d", houseid);
		SendClientMessage(playerid, COLOR_WHITE, string);
    
	}
	return 1;
}
Another point out: SystemStats[HouseCount] is not linked to the issue as it doesn't effect the House ID counting and is a separate feature without a link to the MySQL.

I also cleared all the data and reset the AUTO_INCREMENT to 0 and tried again, however no luck.

I'm sure it's the issue when using the createhouse command, because all the houses appear under the ID of "0", but in the table it's said to be a different ID (unique ID), however when I restart the server it work as it's meant to. So the issue lies within the command of createhouse.

Thanks for your help!
Reply
#2

Help?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)