MySQL fetching row problem! [URGENT HELP]
#1

Hello!

So, today I decided to do the hardware ban system! Anyways, have done everything, but it seems that tinniest and easist part of MySQL/script f*** me up! If you know whats the problem here, please help me!

Here is the code:
pawn Код:
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;
}
And now look at the debug when I use HWBan:
Код:
[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"
Can somebody help me??
Reply
#2

Can someone help me, please? (sorry for bump, but I need this)
Reply
#3

phwid[playerid] is a intenger isn't it?
And you use %s for this inside your query.
So I think you did something wrong with the format, you should take a look at that.
Reply
#4

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.
Reply
#5

Quote:
Originally Posted by fordawinzz
Посмотреть сообщение
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.
So, what should I do then?
Reply
#6

I don't understand what exactly your system is trying to do. It will get the "hwid" of all resulting players, but only uses the last one of them? If I understand you correctly and it looks like you only use ONE field, not any others, you can optimize and simplify your querying process a lot.

pawn Код:
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);
There's no need to use the player's hwid array. But I just didn't because I don't know if you have that created as a proper array. I hope this helps you at least a little.
Reply
#7

Works, thank you! rep+
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)