Jump to content

MySQL Query doesn't work


myonlake

Recommended Posts

Hello there,

I am trying to make a script that kills the player, creates a pedestrian on it and deletes the database entry from the database (deletes character fully).

SQL connection works fine, but debug says the problem is in the query, help?

function characterkill(player, cmd, names) 
    if hasObjectPermissionTo(player, "command.ban") then 
        if names then 
            local other, name = exports.players:getFromName(player, names) 
            if other then 
                connect = mysql_connect("host", "user", "pass", "db") 
                if not connect then 
                    outputDebugString("Unable to connect to the MySQL server.") 
                else 
                    if mysql_query(connect, "DELETE FROM characters WHERE characterName = " .. name) then 
                        local x, y, z = getElementPosition(other) 
                        local skin = getElementModel(other) 
                        local ped = createPed(skin, x, y, z) 
                        setElementHealth(other, 0) 
                        killPed(ped) 
                        setElementFrozen(ped, true) 
                        setElementFrozen(other, true) 
                        setElementAlpha(other, 0) 
                        outputChatBox(name .. " has been character killed.", player, 220, 220, 0, false) 
                        outputChatBox(name .. " has been character killed - meaning that your character is now fully dead and removed.", other, 220, 220, 0, false) 
                        setTimer(redirectPlayer, 5000, 1, other, ip, "22004") 
                    else 
                        outputChatBox("SQL error happened, report at Mantis.", player, 255, 0, 0, false) 
                    end 
                end 
            else 
                outputChatBox("No player found.", player, 255, 0, 0, false) 
            end 
        else 
            outputChatBox("Syntax: /ck [player]", player, 255, 255, 255, false) 
        end 
    end 
end 
addCommandHandler("ck", characterkill) 
 
Edited by myonlake
Link to comment

Try

function characterkill(player, cmd, names) 
    if hasObjectPermissionTo(player, "command.ban") then 
        if names then 
            local other, name = exports.players:getFromName(player, names) 
            if other then 
                connect = mysql_connect("host", "user", "pass", "db") 
                if not connect then 
                    outputDebugString("Unable to connect to the MySQL server.") 
                else 
                    if mysql_query( connect, "DELETE FROM characters WHERE characterName = '" .. name.."'" ) then 
                        local x, y, z = getElementPosition(other) 
                        local skin = getElementModel(other) 
                        local ped = createPed(skin, x, y, z) 
                        setElementHealth(other, 0) 
                        killPed(ped) 
                        setElementFrozen(ped, true) 
                        setElementFrozen(other, true) 
                        setElementAlpha(other, 0) 
                        outputChatBox(name .. " has been character killed.", player, 220, 220, 0, false) 
                        outputChatBox(name .. " has been character killed - meaning that your character is now fully dead and removed.", other, 220, 220, 0, false) 
                        setTimer(redirectPlayer, 5000, 1, other, ip, "22004") 
                    else 
                        outputChatBox("SQL error happened, report at Mantis.", player, 255, 0, 0, false) 
                    end 
                end 
            else 
                outputChatBox("No player found.", player, 255, 0, 0, false) 
            end 
        else 
            outputChatBox("Syntax: /ck [player]", player, 255, 255, 255, false) 
        end 
    end 
end 
addCommandHandler("ck", characterkill) 

You can also check problem with function mysql_error.

And show what debug write.

Edited by Guest
Link to comment

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...