ben_wright Posted May 6, 2012 Posted May 6, 2012 debugscript. this line: local acc = mysql_query(connect, "SELECT * FROM `accounts` WHERE `login` = '"login"' AND `password` = '"pass"'") syntax errors. Post the current code, server & client you are using.
#DaMiAnO Posted May 7, 2012 Author Posted May 7, 2012 My current code: local screenWidth, screenHeight = guiGetScreenSize() function createDxOnLogin() dxDrawRectangle(769.0, 379.0, 211.0, 193.0, tocolor(255, 0, 0, 155), false) dxDrawText("Ping: "..tostring(getPlayerPing(getLocalPlayer())).."\n\n\n FPS: 0",778.0, 387.0, 970.0, 542.0, tocolor(255, 255, 255, 255), 1.0, "bankgothic", "left", "top", false, false, false) dxDrawRectangle(358.0, 379.0, 404.0, 193.0, tocolor(255, 192, 0, 155), false) dxDrawText("Rejestracja", 358.0, 380.0, 574.0, 418.0, tocolor(255, 255, 255, 255), 1.0, "bankgothic", "left", "top", false, false, false) dxDrawRectangle(769.0, 178.0, 211.0, 193.0, tocolor(0, 255, 0, 155), false) dxDrawText("Online:\n\n 1 / 100", 776.0, 180.0, 962.0, 215.0, tocolor(255, 255, 255, 255), 1.0, "bankgothic", "left", "top", false, false, false) dxDrawRectangle(358.0, 178.0, 404.0, 194.0, tocolor(0, 96, 255, 155), false) dxDrawText("Logowanie", 361.0, 180.0, 547.0, 215.0,tocolor(255, 255, 255,255), 1.0, "bankgothic", "left", "top", false, false, false) end function createGUIElements() loginButton = guiCreateButton(634, 323, 117, 37, "Zaloguj!", false) loginPassLabel = guiCreateLabel(481, 244, 48, 56, "Login:\n\n\nHaslo:", false) guiSetFont(loginPassLabel,"default-bold-small") registerLabel = guiCreateLabel(363, 424, 397, 86, "Jesli nie posiadasz konta, udaj sie na nasze forum i zarejestruj konto.\nKolejnym krokiem bedzie zalozenie postaci.\n\n\n[url=http://www.LostHeaven.pl]http://www.LostHeaven.pl[/url]", false) guiSetFont(registerLabel,"default-bold-small") loginBox = guiCreateEdit(525, 241, 145, 23, "", false) guiEditSetMaxLength(loginBox, 25) passBox = guiCreateEdit(525, 281, 145, 23, "", false) guiEditSetMasked(passBox, true) guiEditSetMaxLength(passBox, 30) keyImage = guiCreateStaticImage(358, 237, 111, 94, "key.png", false) guiSetVisible(loginButton, true) guiSetVisible(loginPassLabel, true) guiSetVisible(registerLabel, true) guiSetVisible(loginBox, true) guiSetVisible(passBox, true) guiSetVisible(keyImage, true) addEventHandler("onClientGUIClick", loginButton, clientSubmitLogin, false) end addEventHandler("onClientResourceStart",resourceRoot,function() createGUIElements() showCursor(true) guiSetInputEnabled(true) addEventHandler("onClientRender", root, createDxOnLogin) end) addEvent("tryAgain", true) function clientSubmitLogin(button,state) if button == "left" and state == "up" then local login = guiGetText(loginBox) local pass = guiGetText(passBox) if login and pass then triggerServerEvent("submitLogin", getRootElement(), login, pass) guiSetVisible(loginButton, false) guiSetVisible(loginPassLabel, false) guiSetVisible(registerLabel, false) guiSetVisible(loginBox, false) guiSetVisible(passBox, false) guiSetVisible(keyImage, false) guiSetInputEnabled(false) showCursor(false) else outputChatBox("#EE5555* #C0C0C0Prosze wpisac #EE5555Login #C0C0C0oraz #EE5555Haslo#C0C0C0, aby sie zalogowac!", 255, 255, 255, true) end end end Server: addEvent("submitLogin", true) addEventHandler("submitLogin", root, function(login, pass) local acc = mysql_query(connect, "SELECT * FROM `accounts` WHERE `login` = '"..login.."' AND `password` = '"..pass.."'") if acc then outputChatBox("Zalogowano.", source) triggerClientEvent(client,"close",root) else outputChatBox("#EE5555* #C0C0C0Podano zly #EE5555Login #C0C0C0lub #EE5555Haslo#C0C0C0!", source, 255, 255, 255, true) triggerClientEvent(client, "tryAgain", getRootElement()) end end)
ben_wright Posted May 7, 2012 Posted May 7, 2012 mysql = exports.mysql -- add this anywhere on serverside, and correct it to yours
#DaMiAnO Posted May 7, 2012 Author Posted May 7, 2012 Bugged code: Client: function tryAgainLogin() guiSetVisible(loginButton, true) guiSetVisible(loginPassLabel, true) guiSetVisible(registerLabel, true) guiSetVisible(loginBox, true) guiSetVisible(passBox, true) guiSetVisible(keyImage, true) showCursor(true) guiSetInputEnabled(true) outputChatBox("Test4!", 255, 255, 255, true) addEventHandler("onClientRender", root, createDxOnLogin) end addEvent("tryAgain", true) addEventHandler("tryAgain", getResourceRootElement(getThisResource()), tryAgainLogin) function onPlayerLoginToAccount(login, pass) mysql = exports.mysql local acc = mysql_query(connect, "SELECT * FROM `accounts` WHERE `login` = '"..login.."' AND `password` = '"..pass"'") if acc then outputChatBox("Zalogowano.", source) else outputChatBox("#EE5555* #C0C0C0Podano zły #EE5555Login #C0C0C0lub #EE5555Hasło#C0C0C0!", source, 255, 255, 255, true) triggerClientEvent("tryAgain", getRootElement()) end end addEvent("submitLogin", true) addEventHandler("submitLogin", root, onPlayerLoginToAccount) attempt to call local 'pass' (a string value)
hxv Posted May 7, 2012 Posted May 7, 2012 local acc = mysql_query(connect, "SELECT * FROM `accounts` WHERE `login` = '" .. login .. "' AND `password` = '" .. pass .. "'")
#DaMiAnO Posted May 7, 2012 Author Posted May 7, 2012 local acc = mysql_query(connect, "SELECT * FROM `accounts` WHERE `login` = '" .. login .. "' AND `password` = '" .. pass .. "'") Now: bad argument #1 to 'mysql_query' (mysqlHandler expected, got nil)
Castillo Posted May 7, 2012 Posted May 7, 2012 You haven't connected to the MySQL server, and "connect" variable is nil.
#DaMiAnO Posted May 7, 2012 Author Posted May 7, 2012 @UP: Nope, I'm connected to MySQL. connect = mysql_connect("localhost", "root", "", "lh") if(connect) then outputServerLog("\n[MySQL] Pomyslnie polaczono z MySQL!") outputDebugString("Pomyslnie polaczono z MySQL!", 3, 0, 224, 0) else outputServerLog("\n[MySQL] Wystapil blad podczas laczenia z MySQL! Polaczenie zostalo zerwane...") outputDebugString("Wystapil blad podczas laczenia z MySQL! Polaczenie zostalo zerwane...", 3, 255, 0, 0) mysql_close(connect) end
Castillo Posted May 7, 2012 Posted May 7, 2012 May I ask why are you using Ryden's MySQL module? you could use the built-in MySQL functions which are a lot easier to use. dbConnect dbExec dbQuery dbPoll dbFree
Chamberlien Posted May 8, 2012 Posted May 8, 2012 Using a already made MySQL resource such as the MTA-paradise one is good to use for your simple SQL daily life.
#DaMiAnO Posted May 8, 2012 Author Posted May 8, 2012 May I ask why are you using Ryden's MySQL module? you could use the built-in MySQL functions which are a lot easier to use. dbConnect dbExec dbQuery dbPoll dbFree Because, MySQL module by Ryden is easier for me.
ben_wright Posted May 8, 2012 Posted May 8, 2012 mysql = exports.mysql -- add this anywhere on serverside, and correct it to yours Still got this, right?
#DaMiAnO Posted May 8, 2012 Author Posted May 8, 2012 mysql = exports.mysql -- add this anywhere on serverside, and correct it to yours Still got this, right? Yes.
ben_wright Posted May 8, 2012 Posted May 8, 2012 fairly bad with mysql, give this a try mysql = exports.mysql function onPlayerLoginToAccount(login, pass) local acc = mysql_query(handler, "SELECT * FROM `accounts` WHERE `login` = '" .. login .. "' AND `password` = '" .. pass .. "'") if acc then outputChatBox("Zalogowano.", source ) else outputChatBox("#EE5555* #C0C0C0Podano zły #EE5555Login #C0C0C0lub #EE5555Hasło#C0C0C0!", source, 255, 255, 255, true ) triggerClientEvent("tryAgain", root ) else if (not acc) then outputChatBox("mySQL error", try again, source ) end end end addEvent("submitLogin", true) addEventHandler("submitLogin", root, onPlayerLoginToAccount)
#DaMiAnO Posted May 8, 2012 Author Posted May 8, 2012 Server: function onPlayerLoginToAccount(login, pass) local query = dbQuery(connect, "SELECT * FROM `accounts` WHERE `login` = '%s' AND `pass` = '%s'", login, pass) local acc = dbPoll(query, 0) if acc then outputChatBox("Zalogowano.", source ) else outputChatBox("#EE5555* #C0C0C0Podano zły #EE5555Login #C0C0C0lub #EE5555Hasło#C0C0C0!", source, 255, 255, 255, true ) triggerClientEvent("tryAgain", root ) end end addEvent("submitLogin", true) addEventHandler("submitLogin", root, onPlayerLoginToAccount) [2012-05-08 17:11:36] WARNING: Login\Login_s.lua:2: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil][2012-05-08 17:11:36] WARNING: Login\Login_s.lua:3: Bad argument @ 'dbPoll' [Expected db-query at argument 1, got boolean]
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