Jump to content

Failed to insert row in MySQL


Recommended Posts

Alright, using that login works perfectly but still fails to retrieve the data (I presume..)

function loginHandler(username,password) 
    local result = mysql_query(handler, "SELECT * FROM accounts WHERE accname='" .. username .. "' AND accpassword='" .. password .. "'") 
    local row = mysql_fetch_row(result) 
    if(row)then 
        outputChatBox("You have successfully logged in!", client, 0, 255, 0) 
        setElementData(client, "logged", 1) 
        setElementData(client, "account:admin", tonumber(row["admin"])) 
        local AStatus = tonumber(row["admin"]) 
        if (AStatus == 1) then 
            outputChatBox("You are playing as a PR Moderator.", client, 0, 0, 255) 
        elseif (AStatus == 2) then 
            outputChatBox("You are playing as a PR Administrator.", client, 0, 0, 255) 
        elseif (AStatus == 3) then 
            outputChatBox("Welcome back, Phoenix.", client, 0, 0, 255) 
        end 
        outputChatBox(mysql_error(handler), client, 255, 0, 0) 
        return true 
    else 
        outputChatBox("Your username and/or password is incorrect!", client, 255, 0, 0) 
        triggerClientEvent(client, "displayLogin", getRootElement()) 
        return false 
    end 
end 
addEvent("submitLogin",true) 
addEventHandler("submitLogin",root,loginHandler) 

Tried both variations on row["admin"] or row[1]["admin"]

Link to comment
function loginHandler(username,password) 
    local result = mysql_query(handler, "SELECT * FROM accounts WHERE accname='" .. username .. "' AND accpassword='" .. password .. "'") 
    local row = mysql_fetch_assoc(result) 
    if(result)then 
        outputChatBox("You have successfully logged in!", client, 0, 255, 0) 
        setElementData(client, "logged", 1) 
        setElementData(client, "account:admin", tonumber(row["admin"])) 
        local AStatus = tonumber(row["admin"]) 
        if (AStatus == 1) then 
            outputChatBox("You are playing as a PR Moderator.", client, 0, 0, 255) 
        elseif (AStatus == 2) then 
            outputChatBox("You are playing as a PR Administrator.", client, 0, 0, 255) 
        elseif (AStatus == 3) then 
            outputChatBox("Welcome back, Phoenix.", client, 0, 0, 255) 
        end 
        return true 
    else 
        outputChatBox("Your username and/or password is incorrect!", client, 255, 0, 0) 
        triggerClientEvent(client, "displayLogin", getRootElement()) 
        return false 
    end 
end 
addEvent("submitLogin",true) 
addEventHandler("submitLogin",root,loginHandler) 

Try my code, I tested in my localhost.

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