Mysql error
#1

Hey im having an error with my sql.

Code:
pawn Код:
format(query, sizeof(query), "SELECT `id_member` FROM `members` WHERE `member_name` = '%s'",playerName);
mysql_query(query, MYSQL_RESULT_REGISTER, playerid, connection);
mysql_store_result(connection);
mysql_fetch_field("id_member",result,connection);
Error:
Quote:

[02:42:01] [MySQL] Error (0): Function: mysql_store_result called when no prior successful query executed.
[02:42:01] [MySQL] Error (0): Function: mysql_fetch_field called when no result stored.
[02:42:01] [MySQL] Error (0): Could not execute query. Unknown column 'aqweqaaw' in 'where clause'.

whats wrong with the query?
Fix = +rep
Reply
#2

Try something like:

pawn Код:
new VariableToStoreMemberID;
format(query, sizeof(query), "SELECT * FROM members WHERE member_name = '%s'", playerName);
mysql_query(query); // Execute the formatted query
mysql_store_result(); // Store the results of the query
while(mysql_fetch_row(query, "|"))
{
    mysql_fetch_field("member_id", query); VariableToStoreMemberID = strval(query); // Get the value from member_id field and turn it into a int instead of a string. (that is if you're saving it as a VARCHAR or alike)
}
Not sure which MySQL version you're using as there's many. I'm using Strickend's or whatever his name is and this should work fine for that.
Reply
#3

as I can see this is threaded, you should add this in OnQueryFinish or how ever function is called.
Can you just tell us which version of mysql plugin are you using?
Reply
#4

Quote:
Originally Posted by OsteeN
Посмотреть сообщение
Try something like:

pawn Код:
new VariableToStoreMemberID;
format(query, sizeof(query), "SELECT * FROM members WHERE member_name = '%s'", playerName);
mysql_query(query); // Execute the formatted query
mysql_store_result(); // Store the results of the query
while(mysql_fetch_row(query, "|"))
{
    mysql_fetch_field("member_id", query); VariableToStoreMemberID = strval(query); // Get the value from member_id field and turn it into a int instead of a string. (that is if you're saving it as a VARCHAR or alike)
}
Not sure which MySQL version you're using as there's many. I'm using Strickend's or whatever his name is and this should work fine for that.
Im also using strickenkids plugin, will try this
Reply
#5

if it doesn't work, try threaded way, as you already have defined query ID
Reply
#6

Still cant get it working, what i got now:

pawn Код:
format(query, sizeof(query), "INSERT INTO smf_members (member_name, passwd, real_name, date_registered) VALUES ('%s', SHA1('%s'), '%s', '%i')",playerName, escapedPass, playerName, Seconds);
mysql_query(query, MYSQL_MEMBER_ID, playerid, connection);
pawn Код:
case MYSQL_MEMBER_ID:
        {  
            new myName[24];
            GetPlayerName(spareid, myName, sizeof(myName));
            format(playerData[spareid][playerNamee], 24, "%s", myName);
            new VariableToStoreMemberID, query[300];
            format(query, sizeof(query), "SELECT `id_member` FROM `smf_members` WHERE member_name = '%s' LIMIT 1", playerData[spareid][playerNamee]);
            mysql_query(query); // Execute the formatted query
            mysql_store_result(); // Store the results of the query
            while(mysql_fetch_row(query, "|"))
            {
                mysql_fetch_field("id_member", query);
                VariableToStoreMemberID = strval(query); // Get the value from member_id field and turn it into a int instead of a string. (that is if you're saving it as a VARCHAR or alike)
                format(query, sizeof(query), "INSERT INTO smf_log_online (session, log_time, id_member, id_spider, ip, url) VALUES (0, 0, '%d', 0, 0, 0)",VariableToStoreMemberID);
                mysql_query(query);
            }
            mysql_free_result();
        }
Quote:

[12:24:54] [MySQL] Error (0): Function: mysql_store_result called when no result stored.

Reply
#7

SELECT query also need to be threaded
Reply
#8

What do you mean?
Reply
#9

as you done for insert query, do for select, thread it and do this:

pawn Код:
mysql_store_result(); // Store the results of the query
            while(mysql_fetch_row(query, "|"))
            {
                mysql_fetch_field("id_member", query);
                VariableToStoreMemberID = strval(query); // Get the value from member_id field and turn it into a int instead of a string. (that is if you're saving it as a VARCHAR or alike)
                format(query, sizeof(query), "INSERT INTO smf_log_online (session, log_time, id_member, id_spider, ip, url) VALUES (0, 0, '%d', 0, 0, 0)",VariableToStoreMemberID);
                mysql_query(query);
            }
            mysql_free_result();
in another case
Reply
#10

this is for SELECT
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)