Jump to content

[HELP] dbExec failed;(1) near "SET": syntax error


Recommended Posts

so I got this error when using UDClogging of Noki

local stdLogged = 0
local db = exports.UDCsql:getConnection()

function adminLog()

end

function stdLog(plr, type1, action, type2)
    if (not plr) or (not type1) or (not action) then return nil end
    if (plr:getType() ~= "player") or (type(type1) ~= "string") or (type(action) ~= "string") then return false end
    if (not type2) then type2 = "N/A" end
end

function adminLog(admin, log_)
    local t = getRealTime().timestamp
    db:exec("INSERT INTO `adminlog` (`name`, `log_`, `datum`) VALUES (?, ?, ?)",
        admin,
        log_,
        t
    )
end

function new(plr, type1, action, type2)
    if (not plr or not type1 or not action) then return nil end
    if (type(type1) ~= "string" or type(action) ~= "string") then return false end
    if (not type2) then type2 = "N/A" end
    
    local name
    local accname
    local serial
    
    if (plr and isElement(plr) and plr.type == "player") then
        if (exports.UDCaccounts:isPlayerLoggedIn(plr)) then
            accname = plr.account.name
        else
            accname = "N/A"
        end
        name = plr.name
        serial = plr.serial
    else
        name = tostring(plr)
        accname = "N/A"
        serial = "N/A"
    end
    
    dbExec(db, "INSERT INTO 'logging' SET name= 0, account= ?, type= ?, type2= ?, tick= ?, action= ?, serial= ?",
        name,
        accname,
        type1,
        type2,
        getRealTime{}.timestamp,
        action,
        serial
    )
    stdLogged = stdLogged + 1
    return true
end
function outputTotal(reset)
    if stdLogged ~= 0 then
        outputDebugString("[UDClogging] Total standard logs inserted in the past 5 minutes: "..stdLogged)
    end
    if (reset) then
        stdLogged = 0
    end
end
setTimer(outputTotal, 60000 * 5, 0, true)
addCommandHandler("logged", outputTotal)

-------------------
-- Some stuff we need to log
-------------------

function logConnections()
    -- The account will be guest, so we don't need to worry about the query not being successful
    new(source, "join", "Joined server", source.ip)
end
addEventHandler("onPlayerJoin", root, logConnections)

function logDisconnections(quitType)
    new(source, "quit", tostring(quitType), source.ip)
end
addEventHandler("onPlayerQuit", root, logDisconnections)
--File end

 

Link to post
  • Moderators

You pass 7 args to dbExec, but you have only 6 questionmarks in query string.

And you have to use ` instead of around table/column names.

INSERT INTO `logging` SET name=?, account= ?, type= ?, type2= ?, tick= ?, action= ?, serial= ?

 

Link to post
1 hour ago, 99isme said:

Can you give me an example?

Quote

 



INSERT INTO `logging` SET name=?, account= ?, type= ?, type2= ?, tick= ?, action= ?, serial= ?

 

Your's is 

INSERT INTO `logging` SET name= 0, account= ?, type= ?, type2= ?, tick= ?, action= ?, serial= ?

Notice the 0 for name where should be ?

Edited by Tekken
-
Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...