Asokanta Posted May 4, 2017 Share Posted May 4, 2017 (edited) when i try this code it's never insert datas into database pls help me... ) -- root = getElementRoot() 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( userdata_db, "SELECT * FROM masterdata WHERE username = ?", username ), -1 ) if type(result) ~= 0 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) Console Log : Username = Asokanta WARNING: mysql/serverside.lua:22: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil] WARNING: mysql/serverside.lua:22: Bad argument @ 'dbPoll' [Expected dbquery at argument 1, got boolean] Username = deneme WARNING: mysql/serverside.lua:22: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil] WARNING: mysql/serverside.lua:22: Bad argument @ 'dbPoll' [Expected dbquery at argument 1, got boolean] I Fixed Here* It's giving only login logs but it still don't insert data in database when result isn't 0 New Console Log : LOGIN: (Everyone, Console) Asokanta successfully logged in as 'Asokanta' LOGIN: (Everyone) Asokanta successfully logged in as 'deneme' Database Screenshot : Edited May 4, 2017 by Asokanta Link to comment
Hale Posted May 4, 2017 Share Posted May 4, 2017 WARNING: mysql/serverside.lua:22: Bad argument @ 'dbQuery' [Expecteddb-connection at argument 1, got nil] It says that 'userdata_db' isn't a database connection, meaning you failed to connect to the database. Link to comment
Asokanta Posted May 4, 2017 Author Share Posted May 4, 2017 I fixed this can u read again ? Link to comment
GTX Posted May 4, 2017 Share Posted May 4, 2017 Use dbExec( userdata_db, "INSERT INTO masterdata VALUES (?,?,?,?,?)",username,serial,ip, '',oyuncu) Link to comment
Asokanta Posted May 4, 2017 Author Share Posted May 4, 2017 Why dbExec ? Can u explain pls Link to comment
GTX Posted May 4, 2017 Share Posted May 4, 2017 Because dbQuery returns a handle, with which you can get data from a table using dbPoll. It waits until you use it, so if you free it, it would work. dbExec only executes query, therefore returns nothing. Link to comment
Asokanta Posted May 4, 2017 Author Share Posted May 4, 2017 i tried but allways its giving outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",root, 255, 255, 255, true ) The first code not after this code Link to comment
undefined Posted May 5, 2017 Share Posted May 5, 2017 Can you post your creating table code? If you want to view 'result' table, you can use this: outputConsole(toJSON(result)) 1 Link to comment
GTX Posted May 5, 2017 Share Posted May 5, 2017 local result, num_rows_affected = dbPoll(dbQuery(userdata_db,"SELECT * FROM masterdata WHERE username = ?",username),-1) if num_rows_affected ~= 0 then outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",root,255,255,255,true) else dbExec(userdata_db,"INSERT INTO masterdata VALUES (?,?,?,?,?)",username,serial,ip,'',oyuncu) end 1 Link to comment
Asokanta Posted May 5, 2017 Author Share Posted May 5, 2017 (edited) THX FOR HELP! Edited May 5, 2017 by Asokanta 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