DaNy3LL 21 Posted December 4, 2014 Share Posted December 4, 2014 (edited) Hello guys, I wrote a function to select the value from a table field (has default value set to 0) function check_security() local a = mysql_query("SELECT * FROM account.account WHERE id = "..pc.get_player_id().."") return a.security_status[1] end the function gives this error in syserr attempt to index field `security_status' (a nil value) and this kinda works, but it's not getting the default value of the field (0) - it shows else even if the value in the field is 0 function check_security() local a = mysql_query("SELECT * FROM account.account WHERE id = "..pc.get_player_id().."") return security_status end if check_security() == 0 then say("VALUE 0") else say("OTHER VALUE") end Kind Regards, DaNy3LL Edited August 18, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Endymion 320 Posted December 4, 2014 Share Posted December 4, 2014 int query_select(lua_State* L) { SQLMsg * pMsg = DBManager::instance().DirectQuery(lua_tostring(L, 1)); if (pMsg != NULL) { if (pMsg->Get()->uiNumRows == 0) { M2_DELETE(pMsg); return 0; } MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult); long long wynik_query = 0; str_to_number(wynik_query, row[0]); M2_DELETE(pMsg); lua_pushnumber(L, wynik_query); return 1; } return 0; } return query_select("select security_code from account.account where id = "..pc.get_account_id()..";") 2 Link to comment Share on other sites More sharing options...
DaNy3LL 21 Posted December 4, 2014 Author Share Posted December 4, 2014 Thanks , it works now But how can I set "security_status" field value to 1 function set_as_status(status) local a = mysql_query("UPDATE account.account SET security_status = "..status.." WHERE id = "..pc.get_player_id().."") end This doesn't update the value Link to comment Share on other sites More sharing options...
Endymion 320 Posted December 5, 2014 Share Posted December 5, 2014 Not tested, but try it. int query_update(lua_State* L) { DBManager::instance().Query(lua_tostring(L, 1)); return 0; } 2 Link to comment Share on other sites More sharing options...
DaNy3LL 21 Posted December 5, 2014 Author Share Posted December 5, 2014 The problem was actually that pc.get_player_id() needed to be replaced to pc.get_account_id() , but thanks for your help Link to comment Share on other sites More sharing options...
Benhero 23 Posted December 16, 2014 Share Posted December 16, 2014 This should work: local a = mysql_query("SELECT security_status FROM account.account WHERE id = "..pc.get_account_id().." LIMIT 1") return a[1][1] Greatz Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now