Grzanek Posted October 29, 2021 Share Posted October 29, 2021 Hi, my login panel does not save players to the database and when I want to register I get a message that such a player already exists function registerAccount(login, password, email, reference) local checkUsername = exports.nl_mysql:query("SELECT UID FROM `nl_accounts` WHERE `login` = ? LIMIT 1", login) if checkUsername and checkUsername[1] then triggerClientEvent(client, "loginResponseServer", resourceRoot, "A user with this login already exists.", "error") return end Link to comment
The_GTA Posted October 30, 2021 Share Posted October 30, 2021 Helo Grzanek, how about adding debug output using the outputDebugString function at the start of the registerAccount function? For example you could query for the parameters that were put into the function, like this: outputDebugString("login: " .. tostring(login) .. ", email: " .. tostring(email) .. ", ref: " .. tostring(reference)); have you tried inspecting the contents of your SQL database for any conflicting login information? I recommend you to use the NaviCat Lite software. I am not familiar with the query-construction of your SQL resource. Are you sure that you have properly implemented it using dbPrepareString? Link to comment
Grzanek Posted October 30, 2021 Author Share Posted October 30, 2021 this is the script that connects the server to the database Database = {} Database.__index = Database function Database:new(...) local instance = {} setmetatable(instance, Database) if instance:constructor(...) then return instance end return false end function Database:constructor(...) self.database = arg[1] self.host = arg[2] self.username = arg[3] self.password = arg[4] self.func = {} self.func.queryAsyncResponse = function(...) self:queryAsyncResponse(...) end self.func.queryAsyncMultiselectResponse = function(...) self:queryAsyncMultiselectResponse(...) end if self:connect() then return true else return false end end function Database:connect() setRuleValue("dbname", self.database) setRuleValue("dbhost", self.host) setRuleValue("dbuser", self.username) setRuleValue("dbpass", self.password) self.connection = dbConnect("mysql", string.format("dbname=%s;host=%s;unix_socket=/var/run/mysqld/mysqld.sock", self.database, self.host), self.username, self.password, "share=1;multi_statements=1") if self.connection then outputDebugString(string.format("[MYSQL] Connected to the database (%s)", self.database)) self:updateNames() return true else outputDebugString(string.format("[MYSQL] Cannot connect to the database (%s)", self.database), 3, 255, 0, 0) return false end end function Database:query(...) local qh = dbQuery(self.connection, dbPrepareString(self.connection, ...)) if not qh then return false end local result, num_affected_rows, last_insert_id = dbPoll(qh, -1, true) if not result then dbFree(qh) end return result, num_affected_rows, last_insert_id end function Database:queryAsync(data, ...) dbQuery(self.func.queryAsyncResponse, {{data}}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncWithoutResponse(...) dbQuery(function(qh) dbPoll(qh, 0, true) end, {}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncResponse(qh, data) local result, num_affected_rows, last_insert_id = dbPoll(qh, 0, true) triggerEvent(data[1].callback, resourceRoot, data[1], result, num_affected_rows, last_insert_id) end function Database:queryAsyncMultiselect(data, ...) dbQuery(self.func.queryAsyncMultiselectResponse, {{data}}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncMultiselectResponse(qh, data) local result, num_affected_rows, last_insert_id = dbPoll(qh, 0, true) triggerEvent(data[1].callback, resourceRoot, data[1], result, num_affected_rows, last_insert_id) end function Database:queryMultiselect(...) local qh = dbQuery(self.connection, dbPrepareString(self.connection, ...)) if not qh then return false end local result, num_affected_rows, last_insert_id = dbPoll(qh, -1, true) if not result then dbFree(qh) end return result, num_affected_rows, last_insert_id end function Database:updateNames() self:query("SET NAMES utf8") end local connection function createMysql() connection = Database:new("database", "host", "username", "password") end function query(...) local query, rows, lastID = connection:query(...) return query, rows, lastID end function queryMultiselect(...) local time = getTickCount() local query, rows, lastID = connection:queryMultiselect(...) addDevData(getResourceName(sourceResource), getTickCount() - time, #query) return query, rows, lastID end function queryAsync(callback, ...) connection:queryAsync(callback, ...) end function queryAsyncMultiselect(callback, ...) connection:queryAsyncMultiselect(callback, ...) end function queryAsyncWithoutResponse(...) connection:queryAsyncWithoutResponse(...) end -- Export to dev admin data function addDevData(resourceName, time, results) exports.TR_admin:addMysqlInfo(string.format("Resource: %s Time: %d tick Results: %d", resourceName, time, results)) end createMysql() Link to comment
The_GTA Posted October 30, 2021 Share Posted October 30, 2021 3 hours ago, Grzanek said: this is the script that connects the server to the database The issue does not seem to originate from the code you provide. Please respond to my other two points. 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