SA-MP Forums Archive
Mysql error - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql error (/showthread.php?tid=546693)



Mysql error + REP - Cheesus - 17.11.2014

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


Re: Mysql error - OsteeN - 17.11.2014

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.


Re: Mysql error - CoaPsyFactor - 17.11.2014

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?


Re: Mysql error - Cheesus - 17.11.2014

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


Re: Mysql error - CoaPsyFactor - 17.11.2014

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


Re: Mysql error - Cheesus - 17.11.2014

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.




Re: Mysql error - CoaPsyFactor - 17.11.2014

SELECT query also need to be threaded


Re: Mysql error - Cheesus - 17.11.2014

What do you mean?


Re: Mysql error - CoaPsyFactor - 17.11.2014

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


Re: Mysql error - Cheesus - 17.11.2014

this is for SELECT