insert_mysl_id(); problem
#1

Hey, i have problem with insert_mysql_id(); It should create a ID to database, but it saves always with 0, so i think, something is wrong. My friend told me something about AUTO_INCREMENT value, but nothing like this, what solve my problem. So i hope, that someone can help me with this
Reply
#2

Show us your code please
Reply
#3

Here it is.

pawn Код:
CMD:teemaja(playerid, params[])
{
new mHind, meX, meY, meZ, mint, mvw = random(9999), aadress[24],Float:fenX, Float:fenY, Float:fenZ, string[80],query[400];
mysql_store_result();
new id = mysql_insert_id();
mysql_free_result();
if(PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid, V_PUNANE, NOTADMIN);
if(sscanf(params,"ifffis[24]", mHind, meX, meY, meZ, mint, aadress)) return SendClientMessage(playerid, V_PUNANE, "KASUTA: /teemaja [Hind][VдljumineX][VдljumineY][VдljumineZ][Interior][Aadress]");
GetPlayerPos(playerid, fenX, fenY, fenZ);
if(mint > 99) return SendClientMessage(playerid, V_PUNANE, "Maja interiццr vali valikus 1-99");
if(strlen(aadress) > 24) return SendClientMessage(playerid, V_PUNANE, "Maja aadress vali vahemikus 1-24 tдhemдrki");
format(string, sizeof(string), "[MЬЬA]\n%s\nHind:%i",aadress, mHind);
format(query, sizeof(query), "INSERT INTO housedata (HouseID, Price, EnterX, EnterY, EnterZ, ExitX, ExitY, ExitZ, Interior, World, Text, Owner, Owned, Locked) VALUES(%i, %i, %f, %f, %f, %f, %f, %f, %i, %i, '%s', 'None', 0, 0)", id, mHind, fenX, fenY, fenZ, meX, meY, meZ, mint, mvw, aadress);
mysql_query(query);
hInfo[id][Label] = Create3DTextLabel(string, COLOR_LIGHTORANGE,fenX,fenY, fenZ, 35.0, 0, 0);
hInfo[id][Pickup] = CreatePickup(1273,23, fenX, fenY, fenZ, -1);
hInfo[id][mID] = id;
hInfo[id][Price] = mHind;
hInfo[id][EnterX] = fenX;
hInfo[id][EnterY] = fenY;
hInfo[id][EnterZ] = fenZ;
hInfo[id][ExitX] = meX;
hInfo[id][ExitY] = meY;
hInfo[id][ExitZ] = meZ;
hInfo[id][mInterior] = mint;
hInfo[id][World] = mvw;
hInfo[id][Text] = aadress;
return 1;
}
Reply
#4

This is completely wrong. mysql_insert_id in itself doesn't generate an id. It merely retrieves the last id that was created by the MySQL Server (i.e. AFTER the insert was performed). Yes, you need auto increment on that field. In phpMyAdmin this is merely ticking a checkbox.
Reply
#5

Okay, now it generated and saved the ID, but its always the same. If i made a 2 houses in a row, it saved ID 4 to both of it.

//E:Okay, i fixed it. I used mysql_insert_id()+1;.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)