FSXTim Posted June 27, 2012 Share Posted June 27, 2012 (edited) Hello, I have a small problem again. DebugString: Unknown 'Name' in 'where clause'. And also the DebugString doesn't say 'Test'. First script: function bann (nick, ip, username, serial) local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") if bt then bool = not (bt == 0) end if bool then if bt > 0 then outputDebugString("Test") cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bann) Second script: function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE "..bedingung) if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Greets Edited June 27, 2012 by Guest Link to comment
-ffs-Sniper Posted June 27, 2012 Share Posted June 27, 2012 Everything seems to be fine for me. Either the table does not exist or you have selected a wrong database. Without a screenshot of the MySQL structure and the LUA code where the connection info is stored we can not help you much. Link to comment
FSXTim Posted June 27, 2012 Author Share Posted June 27, 2012 It's working now. Sorry, it was my mistake. But no I have another problem. DebugString: Unknown 'Name' in 'where clause'. And also the DebugString doesn't say 'Test'. First script: function bann (nick, ip, username, serial) local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") if bt then bool = not (bt == 0) end if bool then if bt > 0 then outputDebugString("Test") cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bann) Second script: function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE "..bedingung) if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Greets Link to comment
Castillo Posted June 27, 2012 Share Posted June 27, 2012 That's because is wrong syntax. local result = mysql_query(sqlcon, "SELECT ".. feldN .." FROM ".. tableN .." WHERE columnName = ".. bedingung .."") Link to comment
FSXTim Posted June 27, 2012 Author Share Posted June 27, 2012 Thanks, Solidsnake14, but I had to change it to: function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, username).."';") if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Error: Bad argument #2 'mysql_escape_string' (string expected, got nil) Greets Link to comment
Castillo Posted June 27, 2012 Share Posted June 27, 2012 function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") -- Your argument is: "bedingung", not "username". if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Read comment. Link to comment
FSXTim Posted June 27, 2012 Author Share Posted June 27, 2012 Thanks, no more errors in the second script. But I have one problem, the DebugString doesn't say 'Test' and the event isn't canceled. Error (line 3): attempt to compare number with boolean function bannCheck (nick, ip, username, serial) local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") if bt > 0 then outputDebugString("Test") cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bannCheck) Greets Link to comment
FSXTim Posted June 27, 2012 Author Share Posted June 27, 2012 I know that, but how can I fix it? Greets Link to comment
Anderl Posted June 27, 2012 Share Posted June 27, 2012 There's no way until you show the function Mysql_GetString/Mysql structure. Link to comment
FSXTim Posted June 27, 2012 Author Share Posted June 27, 2012 function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Greets Link to comment
Anderl Posted June 27, 2012 Share Posted June 27, 2012 Here: local savename = feldname In your MySQL_GetString function, I didn't see. "feldname" is not declarated. Link to comment
FSXTim Posted June 28, 2012 Author Share Posted June 28, 2012 What do you mean? What do I have to change? I think I found the problem. The DebugString sais 'Test', indifferent what 'Bann' is. It can be 0, 5 or 10 (line 13). The DebugString sais '0', although 'Bann' is '15' (line 6). function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") if (not result) then outputDebugString(mysql_error(sqlcon)) else outputDebugString(mysql_num_rows(result)) if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldN mysql_free_result(result) return ds[feldN] else outputDebugString("Test!") mysql_free_result(result) return false end end end What do I have to do to fix it? Greets Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now