stock HWBan(playerid)
{
new PNAME[MAX_PLAYER_NAME];
GetPlayerName(playerid,PNAME,sizeof(PNAME));
new PlayerIP[20];
new phwid[MAX_PLAYERS];
GetPlayerIp(playerid,PlayerIP,sizeof(PlayerIP));
new hquery[100];
format(hquery, sizeof(hquery), "SELECT * FROM hwuser WHERE name = '%s'", PNAME);
mysql_query(hquery);
mysql_store_result();
while(mysql_fetch_row_format(hquery,"|"))
{
new hwstring[100];
mysql_fetch_field_row(hwstring,"hwid"); phwid[playerid] = strval(hwstring);
}
mysql_free_result();
new hquery2[200];
format(hquery2, sizeof(hquery2), "INSERT INTO hwbans(name, hwid, IP) VALUES('%s', '%s', '%s')", PNAME, phwid[playerid], PlayerIP);
mysql_query(hquery2);
Kick(playerid);
return 1;
}
[22:44:44] CMySQLHandler::Query(SELECT * FROM hwuser WHERE name = 'fiki574_CRO') - Successfully executed. [22:44:44] >> mysql_store_result( Connection handle: 1 ) [22:44:44] CMySQLHandler::StoreResult() - Result was stored. [22:44:44] >> mysql_fetch_row_format( Connection handle: 1 ) [22:44:44] CMySQLHandler::FetchRow() - Return: fiki574_CRO|00x01054716159|127.0.0.1 [22:44:44] >> mysql_fetch_field_row( Connection handle: 1 ) [22:44:44] CMySQLHandler::FetchField("hwid") - 00x01054716159 //this is number that I need, it is fetched here, but now look down [22:44:44] >> mysql_fetch_row_format( Connection handle: 1 ) [22:44:44] >> mysql_free_result( Connection handle: 1 ) [22:44:44] CMySQLHandler::FreeResult() - Result was successfully free'd. [22:44:44] >> mysql_query( Connection handle: 1 ) [22:44:45] CMySQLHandler::Query(INSERT INTO hwbans(name, hwid, IP) VALUES('fiki574_CRO', 'HWID HERE', '127.0.0.1')) - Successfully executed. //previous number (00x01054716159) should be instead of "HWID HERE" at "VALUES"
It is wrong because you used strval(string -> val) so your number will be an integer value and you try to save phwid as a string, that's wrong.
![]() |
format(hquery, sizeof(hquery), "SELECT hwid FROM hwuser WHERE name = '%s'", PNAME);
mysql_query(hquery);
mysql_store_result();
// If you're not 100% sure about results, also include a mysql_num_rows check
new hw_id[15]; // change to a higher value if the ids are longer in some case
mysql_fetch_row(hw_id);
mysql_free_result();
// now REUSE the previous hquery string, no need for a new one!
format(hquery, sizeof(hquery), "INSERT INTO hwbans(name, hwid, IP) VALUES('%s', '%s', '%s')", PNAME, hw_id, PlayerIP);
mysql_query(hquery);
Kick(playerid);