Jump to content

I Need help for mysql result


Recommended Posts

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.

Link to comment

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
Link to comment

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 ?

Link to comment

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 . .
Link to comment

when i try command it inserting all the time

 

Console log : mysql/serverside.lua:22: Bad argument @ 'dbPoll' [Expected dbquery at argument 1, got boolean] (in your code 22 is 8   )

 

Edited by Asokanta
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...