Asokanta Posted May 3, 2017 Posted May 3, 2017 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.
Simple. Posted May 3, 2017 Posted May 3, 2017 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) 1
Asokanta Posted May 3, 2017 Author Posted May 3, 2017 Dude,i think you saved my life. I will try this code when i go online.
Asokanta Posted May 3, 2017 Author Posted May 3, 2017 I tested the script but there is a problem: When i login its adding data to database all the time its bypassing the code and just insert data allways...
undefined Posted May 3, 2017 Posted May 3, 2017 I don't use social media. You can contact me only here with private message.
Asokanta Posted May 3, 2017 Author Posted May 3, 2017 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 ?
Simple. Posted May 3, 2017 Posted May 3, 2017 local sorgu = dbQuery( userdata_db, "INSERT INTO `masterdata`(`username`, `serial`, `ip` ,`puan` , `name`) VALUES (?,?,?,'',?)",username,serial,ip,oyuncu) what is `puan` for ?
Asokanta Posted May 3, 2017 Author Posted May 3, 2017 (edited) It means point but point need to be empty Edited May 3, 2017 by Asokanta
Simple. Posted May 3, 2017 Posted May 3, 2017 (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 May 3, 2017 by 'SimpleArtS . .
Asokanta Posted May 4, 2017 Author Posted May 4, 2017 (edited) 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 May 4, 2017 by Asokanta
Simple. Posted May 4, 2017 Posted May 4, 2017 make sure the db variable 'usedata' isn't local in some function
Asokanta Posted May 4, 2017 Author Posted May 4, 2017 (edited) Nobody can't help ? Edited May 4, 2017 by Asokanta
keymetaphore Posted May 4, 2017 Posted May 4, 2017 dbPoll( dbQuery( usedata_db it's usedata_db here dbQuery( userdata_db, "INS and userdata_db here do you have 2 variables or you typed it incorrectly? @Asokanta
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