Answer the question
In order to leave comments, you need to log in
Why does MySQL return an empty value?
I am doing registration with duplication of data in the database for the game Multi Theft Auto.
inputs[1] and inputs[2] - login and password (only letters and numbers)
After registration, the user is written to the database. The rest of the default values are set in the database.
If the write to the database is successful, then the script again accesses the database and searches for the player's data by nickname and gets the rest of the data, then spawns the user, gives him money, etc.
PROBLEM:
local sNewUser = query("SELECT * FROM `userinfo` WHERE `nickname` = '"..tostring(inputs[1]).."'")
local sNewUser = query("SELECT * FROM `userinfo` WHERE `nickname` = 'test'")
local dbHost = 'localhost'
local dbName = 'test'
local dbUsername = 'root'
local dbPassword = ''
function query(...)
local queryHandle = dbQuery(dbConnect('mysql','host='..dbHost..';dbname='..dbName, dbUsername, dbPassword), ...)
if (not queryHandle) then
return nil
end
local rows = dbPoll(queryHandle, -1)
return rows
end
local nA = addAccount(inputs[1], inputs[2]) -- добавляем юзера в игру
local addA = query("INSERT INTO `userinfo` ('serial', 'nickname', 'password', 'team') VALUES ('"..tostring(getPlayerSerial(client)).."', '"..tostring(inputs[1]).."', '"..tostring(inputs[2]).."')") -- добавляем игрока в базу
if (nA and addA) then -- если удачно добавился
local sNewUser = query("SELECT * FROM `userinfo` WHERE `nickname` = '"..tostring(inputs[1]).."'") -- ищем игрока в базе по имени
if (sNewUser) then
for _, row in ipairs(sNewUser) do -- перебираем данные из базы
posX = row['posX'] -- позиция X
posY = row['posY'] -- позиция Y
posZ = row['posZ'] -- позиция Z
usrHealth = row['health'] -- здоровье
w11 = row['w11'] -- 11 слот оружия
usrTeam = row['team'] -- команда
usrSkinID = row['skin'] -- скин
usrMoney = row['money'] -- деньги
usrArmor = row['armor'] -- броня
outputDebugString('posX: '..posX)
outputDebugString('posY: '..posY)
outputDebugString('posZ: '..posZ)
outputDebugString('usrHealth: '..usrHealth)
outputDebugString('w11: '..w11)
outputDebugString('usrTeam: '..usrTeam)
outputDebugString('usrSkinID: '..usrSkinID)
outputDebugString('usrMoney: '..usrMoney)
outputDebugString('usrArmor: '..usrArmor)
end
logIn(client, nA, inputs[2]) -- логиним юзера
spawnPlayer(client, posX, posY, posZ, 0, usrSkinID, 0, 0) -- спавн (игрок, позиция x, y, z, положение, скин, интерьер, измерение)
setPlayerMoney (client, usrMoney) -- выдаем деньги
setTimer (setElementHealth, 50, 1, client, usrHealth) -- выдаем здоровье
setTimer (setPedArmor, 50, 1, client, usrArmor) -- выдаем армор
triggerClientEvent(client, "onClientSuccess", client) -- передаем юзеру, что все ок
--setPlayerTeam(client, getTeamFromName("User"))
--setAccountData(nA, "cash", 250000)
--triggerClientEvent(client, "onClientSuccess", client)
else
triggerClientEvent(client, "showErrorMessage", client, "Ошибка")
end
else
triggerClientEvent(client, "showErrorMessage", client, "Ошибка при создании аккаунта.")
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