Jump to content

Failed to insert row in MySQL


Recommended Posts

Posted

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"]

All kinds of feedback are welcome on all of my posts.

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

Ingame nick: Cadu12

Posted

Interesting find, pasted the EXACT code and I get this

ERROR: pf\s_main.lua:17: attempt to index local `row` (a nil value) 

EDIT: Upon further inspection, row["admin"] is failing to be set at all.

All kinds of feedback are welcome on all of my posts.

Posted

I'll try that but if I am not mistaken, the row = mysql_fetch_rows should do that for me?

EDIT: Yea, same problem. Doesn't seem to withdraw the date from row["admin"]

All kinds of feedback are welcome on all of my posts.

Posted

@Cadu, can you send me a SS of what it displays IG?

EDIT: Wait, nevermind I got it fully functional now using the fetch_assoc!

Thanks so much everyone, special thanks to Cadu! :)

All kinds of feedback are welcome on all of my posts.

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