Answer the question
In order to leave comments, you need to log in
MTA (Multi Theft Auto) LUA - What's wrong with my database query?
Hello, I don't understand what is my mistake. What have I done wrong?
The bottom line is this: there is a connection to the database and sql queries (code 1). I'm trying to get a login and password into a variable, but the console gives an error (screenshot 1)
Code 1:
function connect()
db = dbConnect( "mysql", "dbname=users;host=127.0.0.1;charset=utf8", "root", "" )
if (not db) then
outputDebugString("Error: Failed to establish connection to the MySQL database server")
else
dbExec(db, "CREATE TABLE IF NOT EXISTS users (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, login VARCHAR(32), password VARCHAR(24), status INT, hp INT, money INT, level INT)")
outputDebugString("Success: Connected to the MySQL database server")
end
end
addEventHandler("onResourceStart",resourceRoot, connect)
function playerRegister(login, password)
local player = source
local mylogin = getAccount(login)
local mypassword = getAccount(password)
if not getAccount(login) then
addAccount(login, password)
dbExec(db, "INSERT INTO users(login, password, status, hp, money, level) VALUES("..mylogin..", "..mypassword..", 1, 100, 1500, 16)")
outputChatBox('Аккаунт успешно создан.', player)
else
outputChatBox('Аккаунт с таким логином существует!', player)
end
end
addEvent('playerRegister', true)
addEventHandler('playerRegister', root, playerRegister)
function playerLogin(login, password)
local player = source
local mylogin = getAccount(login)
local mypassword = getAccount(password)
local dblogin = dbQuery(db, "SELECT `login` FROM `users` WHERE login = "..mylogin.."")
local dbpassword = dbQuery(db, "SELECT `password` FROM `users` WHERE login = "..mylogin.."")
if (dblogin == login) then
if (dbpassword == password) then
logIn(player, getAccount(login, password), password)
outputChatBox('Добро пожаловать!', player)
triggerClientEvent(player, 'closePanel', player)
setElementFrozen(source, false)
end
else
outputChatBox('Неправильный логин или пароль!', player)
end
end
addEvent('playerLogin', true)
addEventHandler('playerLogin', root, playerLogin)
addEventHandler('onPlayerJoin', root, function()
triggerClientEvent(source, 'openPanel', source)
setElementFrozen(source, true)
end)
addEventHandler('onPlayerLogout', root, function()
triggerClientEvent(source, 'openPanel', source)
setElementFrozen(source, true)
end)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question