Jump to content

I Need help for mysql result


Recommended Posts

Posted
addEventHandler("onPlayerLogin", root,
  function()
    outputChatBox(getPlayerName(source).." Giriş yapti.", root) 
local oyuncu = getPlayerName(source)
local ip = getPlayerIP(source)
local serial = getPlayerSerial(source)
local account = getPlayerAccount(source)
local username = getAccountName(account)
	local qh = dbQuery( usedata_db, "SELECT * FROM masterdata WHERE username =?",username )
	local result = dbPoll( qh, -1 )
if result == nil then
	local sorgu = dbQuery( userdata_db, "INSERT INTO `masterdata`(`username`, `serial`, `ip` ,`puan` , `name`) VALUES (?,?,?,'',?)",username,serial,ip,oyuncu)
	dbFree( sorgu )
	else
	outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",getRootElement(), 255, 255, 255, true )
	end
	end)

 

in here,i'm saying this : if this username don't exist in database insert data else do nothing.

But when i try the script it gives nothing everytime like exist or don't exist usernames

help pls.

Developer and founder of

T.O.G (Not founded yet.)


 

Posted

try this

addEventHandler("onPlayerLogin", root,
function()
    outputChatBox(getPlayerName(source).." Giriş yapti.", root) 
    local oyuncu = getPlayerName(source)
    local ip = getPlayerIP(source)
    local serial = getPlayerSerial(source)
    local account = getPlayerAccount(source)
    local username = getAccountName(account)
    local result = dbPoll( dbQuery( usedata_db, "SELECT * FROM masterdata WHERE username = ?", username ), -1 )
    if type(result) == "table" and #result ~= 0 and result[1]["username"] == username then
        outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",getRootElement(), 255, 255, 255, true )
    else
        local sorgu = dbQuery( userdata_db, "INSERT INTO masterdata VALUES (?,?,?,'',?)",username,serial,ip,oyuncu)
        dbFree( sorgu )
    end
end)
    

 

  • Like 1
h3x#2020
Posted

Yes,because i can't solve this problem

6 hours ago, Asokanta said:

addEventHandler("onPlayerLogin", root,
  function()
    outputChatBox(getPlayerName(source).." Giriş yapti.", root) 
local oyuncu = getPlayerName(source)
local ip = getPlayerIP(source)
local serial = getPlayerSerial(source)
local account = getPlayerAccount(source)
local username = getAccountName(account)
	local qh = dbQuery( usedata_db, "SELECT * FROM masterdata WHERE username =?",username )
	local result = dbPoll( qh, -1 )
if result == nil then
	local sorgu = dbQuery( userdata_db, "INSERT INTO `masterdata`(`username`, `serial`, `ip` ,`puan` , `name`) VALUES (?,?,?,'',?)",username,serial,ip,oyuncu)
	dbFree( sorgu )
	else
	outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",getRootElement(), 255, 255, 255, true )
	end
	end)

 

in here,i'm saying this : if this username don't exist in database insert data else do nothing.

But when i try the script it gives nothing everytime like exist or don't exist usernames

help pls.

Can anybody help me to solve this problem ?

Developer and founder of

T.O.G (Not founded yet.)


 

Posted
	local sorgu = dbQuery( userdata_db, "INSERT INTO `masterdata`(`username`, `serial`, `ip` ,`puan` , `name`) VALUES (?,?,?,'',?)",username,serial,ip,oyuncu)

 what is `puan` for ?

h3x#2020
Posted (edited)

ok try this

addEventHandler("onPlayerLogin", root,
function(_, account)
    outputChatBox(getPlayerName(source).." Giriş yapti.", root) 
    local oyuncu = getPlayerName(source)
    local ip = getPlayerIP(source)
    local serial = getPlayerSerial(source)
    local username = getAccountName(account)
    local result = dbPoll( dbQuery( usedata_db, "SELECT * FROM masterdata WHERE username = ?", username ), -1 )
    if type(result) == "table" and #result ~= 0 and result[1]["username"] == username then
        outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",root, 255, 255, 255, true )
    else
		dbQuery( userdata_db, "INSERT INTO masterdata VALUES (?,?,?,?,?)",username,serial,ip, '',oyuncu)
    end
end)

 

Edited by 'SimpleArtS . .
h3x#2020

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...