Jump to content

executeSQLQuery


orcun99

Recommended Posts

this is my code

function PlayerLogin(username,password,checksave)
	if not (username == "") then
		if not (password == "") then
			local account = getAccount ( username, password )
			local ip = getPlayerIP(source)
			local serial = getPlayerSerial(source)
			if ( account ~= false ) then
				logIn(source, account, password)
executeSQLQuery("INSERT INTO `hesaplar` VALUES(?,?,?,?)", ip, serial, username, password)
				triggerClientEvent (source,"hideLoginWindow",getRootElement())
				triggerEvent("onPlayerLogIn", source)
				triggerClientEvent(source,"onPlayerLoginSuccess", source)
				setElementData(source,"loggedIn", true)
				setElementData(source,"username", getAccountName(account))
				setElementData(source, "gang", getAccountData(account, "gang"))
				
				local realTime = getRealTime()
				
				local month = tostring(realTime.month + 1)
				local monthday = tostring(realTime.monthday)
				
				if #month == 1 then month = "0" .. month end
				if #monthday == 1 then monthday = "0" .. monthday end
				
				local timestamp = realTime.year + 1900 .. "-" .. month .. "-" .. monthday
				
				setAccountData(account, "lastlogin", timestamp)
				
					if checksave == true then
						triggerClientEvent(source,"saveLoginToXML",getRootElement(),username,password)
					else
						triggerClientEvent(source,"resetSaveXML",getRootElement(),username,password)
					end
				
			else
				triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Hatalı Kullanıcı adı / şifre!")
			end
		else
			triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Şifreni Gir!")
		end
	else
		triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Kullanıcı Adını Gir!")
	end
end


addEvent("onRequestLogin",true)
addEventHandler("onRequestLogin",getRootElement(),PlayerLogin)

this is working..  

but I want   if same serial and same id  logged in then   stop insert into    update before record do not new record

image: kOWRB7.png

Link to comment
function isAccountExists(serialToCheck)
	local data = executeSQLQuery("SELECT * FROM hesaplar")
	if type(data) == "table" and #data ~= 0 then
		for k,v in ipairs(data) do
			if v.serial == serialToCheck then
				return true
			end
		end
	end
	return false
end

function PlayerLogin(username,password,checksave)
	if not (username == "") then
		if not (password == "") then
			local account = getAccount ( username, password )
			local ip = getPlayerIP(source)
			local serial = getPlayerSerial(source)
			if ( account ~= false ) then
				logIn(source, account, password)
				if not isAccountExists(serial) then
					executeSQLQuery("INSERT INTO hesaplar(ip,serial,id,sifre) VALUES(?,?,?,?)", ip, serial, username, password)
				else
					executeSQLQuery("UPDATE hesaplar SET id=?,sifre=? WHERE serial=?",username,password,serial)
				end
				triggerClientEvent (source,"hideLoginWindow",getRootElement())
				triggerEvent("onPlayerLogIn", source)
				triggerClientEvent(source,"onPlayerLoginSuccess", source)
				setElementData(source,"loggedIn", true)
				setElementData(source,"username", getAccountName(account))
				setElementData(source, "gang", getAccountData(account, "gang"))
				
				local realTime = getRealTime()
				
				local month = tostring(realTime.month + 1)
				local monthday = tostring(realTime.monthday)
				
				if #month == 1 then month = "0" .. month end
				if #monthday == 1 then monthday = "0" .. monthday end
				
				local timestamp = realTime.year + 1900 .. "-" .. month .. "-" .. monthday
				
				setAccountData(account, "lastlogin", timestamp)
				
					if checksave == true then
						triggerClientEvent(source,"saveLoginToXML",getRootElement(),username,password)
					else
						triggerClientEvent(source,"resetSaveXML",getRootElement(),username,password)
					end
				
			else
				triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Hatalı Kullanıcı adı / şifre!")
			end
		else
			triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Şifreni Gir!")
		end
	else
		triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Kullanıcı Adını Gir!")
	end
end


addEvent("onRequestLogin",true)
addEventHandler("onRequestLogin",getRootElement(),PlayerLogin)

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...