Electrosumm Posted June 2, 2016 Share Posted June 2, 2016 After a year I started again programming and I have some problem.. I want to save to MySQL the player username from edittext and the password from edittext too but the debbuger say its nil value now I m so beginner again can anyone help me ? its an login register script Client Side local en1 = getLocalPlayer() local valami1 = 0 function logpanelkeszites() if(valami1 == 1) then return end valami1 = 1 showCursor(true) guiSetInputMode("no_binds_when_editing") rX,rY = guiGetScreenSize() width,height = 564,379 X = (rX/2) - (width/2) Y = (rY/2) - (height/2) logpanel = guiCreateWindow(X,Y,width,height,"Bejelentkezés",false) -------------------------------------------------------------------- jeledit = guiCreateEdit(45,135,200,40,"",false,logpanel) felhedit = guiCreateEdit(45,200,200,40,"",false,logpanel) bejelentkezesgomb = guiCreateButton(62,265,150,43,"BejelentkezésGomb",false,logpanel) regisztraciogomb = guiCreateButton(230,340,150,40,"RegisztrációsGomb",false,logpanel) addEventHandler ( "onClientGUIClick", regisztraciogomb, register, false ) addEventHandler ( "onClientGUIClick", bejelentkezesgomb, bejelentkezes, false ) ---------------------------------------------------------------------- guiSetVisible(logpanel,true) showCursor(true) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource( ) ),logpanelkeszites ) function register () local text1 = guiGetText(jeledit) if(text1 == "") then return end triggerServerEvent("onFelhasznaloRegisztracio", en1, text1) end function bejelentkezes () local felhasznalonev = guiGetText(felhedit) local jelszo = guiGetText(jeledit) if (felhasznalonev:match("^%s*$")) then outputChatBox("A felhasználónév rublika üres!Kérlek írd be a felhasználóneved!",255,0,0,true) elseif (jelszo:match("^%s*$")) then outputChatBox("A jelszo rublika üres!Kérlek írd be a jelszavad!",255,0,0,true) else outputChatBox("Logging in...",0,255,0,true) triggerServerEvent("onFelhasznaloBejelentkezes", en1, felhasznalonev, jelszo) end end addEventHandler("onClientResourceStart", getResourceRootElement(), function() logpanelkeszites() end) addEvent("onFelhasznaloEllenorzese", true) addEvent("onSikeresBejelentkezes", true) addEventHandler("onSikeresBejelentkezes", getRootElement(), function() destroyElement(logpanel) valami1 = 0 showCursor(false) outputChatBox("Sikeresen Bejelentkeztél!") fadeCamera(true) end) Server Side local mysqlhost = "localhost" local mysqluser = "root" local mysqlpw = "" local mysqldatabase = "mta" handler = mysql_connect ( mysqlhost, mysqluser, mysqlpw, mysqldatabase ) addEvent("onFelhasznaloEllenorzese", true) addEvent("onFelhasznaloRegisztracio", true) addEvent("onFelhasznaloBejelentkezes", true) addEventHandler("onFelhasznaloRegisztracio", getRootElement(), function(password) if not(password) then return end -- ha nincs jelszó local result = mysql_query(handler, "INSERT INTO account (ACCOUNTS , PASSWORD) VALUES (`"..felhasznalonev.."`, `"..jelszo.."`)") if(result) then outputChatBox("Sikeres Regisztráció!", source, 0, 255, 0) -- Sikeres triggerEvent("onFelhasznaloEllenorzese", source) -- Event hívás else outputChatBox("Nem sikerült a regisztráció!", source, 255, 0, 0) -- Nem sikeres end end) addEventHandler("onFelhasznaloBejelentkezes", getRootElement(), function(passwort) -- der Event Handler local result = mysql_query( handler, "SELECT * FROM account WHERE ACCOUNTS = '"..felhasznalonev.."' AND PASSWORD = '"..jelszo.."';" ) if(result and mysql_num_rows( result ) > 0) then triggerClientEvent(source, "onSikeresBejelentkezes", source) -- local row = mysql_fetch_assoc(result) -- setElementData(source, "adminlevel", tonumber(row['ADMINLEVEL']) or 0) addEventHandler("onElementDataChange", source, function(theData, oldValue) local newdata = getElementData(source, theData) if(theData == "adminlevel") then mysql_query(handler, "UPDATE account SET ADMINLEVEL = '"..tonumber(newdata).."' WHERE ACCOUNTS = '"..felhasznalonev.."';") end end) else outputChatBox("Nem jó a jelszó vagy ninsc ilyen felhasználó!", source, 255, 0, 0) end end) Link to comment
Gravestone Posted June 6, 2016 Share Posted June 6, 2016 If you're trying to save username, creating an XML file is the best way to do so. 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