Jump to content

SQL if exist


Jimmy.

Recommended Posts

Posted

I check or row is exist, but always got " Wrong username" even username is in database. Where can be a mistake?

function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=?", username) 
    local result = dbPoll( query, -1 ) 
    if result == true then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=? AND password=?",username,password) 
        local result = dbPoll( query, -1 ) 
        if result then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 
  

Posted

dbPoll doesn't return boolean value.

function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=?", username) 
    local result = dbPoll( query, -1 ) 
    if result then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=? AND password=?",username,password) 
        local result = dbPoll( query, -1 ) 
        if result then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted
dbPoll doesn't return boolean value.
function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=?", username) 
    local result = dbPoll( query, -1 ) 
    if result then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=? AND password=?",username,password) 
        local result = dbPoll( query, -1 ) 
        if result then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 

But now always show: "Welcome to My Server." Or wrong username or no.

Posted

Oh, use this:

function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=?", username) 
    local result = dbPoll( query, -1 ) 
    if #result == 1 then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=? AND password=?",username,password) 
        local result = dbPoll( query, -1 ) 
        if #result == 1 then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

Then you're entering wrong username. Debug the code like:

function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=?", username) 
    local result = dbPoll( query, -1 ) 
    outputChatBox(#result) 
    if #result == 1 then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=? AND password=?",username,password) 
        local result = dbPoll( query, -1 ) 
        if #result == 1 then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 

Also, don't forget to use dbFree.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

It's wrong username. What username did you enter exactly?

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

Maybe. Output username and then compare to the row in the table.

function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=?", username) 
    outputChatBox(username) 
    local result = dbPoll( query, -1 ) 
    outputChatBox(#result) 
    if #result == 1 then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=? AND password=?",username,password) 
        local result = dbPoll( query, -1 ) 
        if #result == 1 then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted
Maybe. Output username and then compare to the row in the table.
function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=?", username) 
    outputChatBox(username) 
    local result = dbPoll( query, -1 ) 
    outputChatBox(#result) 
    if #result == 1 then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=? AND password=?",username,password) 
        local result = dbPoll( query, -1 ) 
        if #result == 1 then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 

outputChatBox(username) here it is okay, what i wrote, output show the same.

I send PM my all clientside file.

Posted

There is no problem in client-sided file.

Try:

function loginHandler(username,password) 
    local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=`??`", username) 
    local result = dbPoll( query, -1 ) 
    outputChatBox(#result) 
    if #result == 1 then 
        local query = dbQuery(handler,"SELECT * FROM accounts WHERE username=`??` AND password=`??`",username,password) 
        local result = dbPoll( query, -1 ) 
        if #result == 1 then 
            if (client) then 
                spawnPlayer(client, 1959.55, -1714.46, 10) 
                fadeCamera(client, true) 
                setCameraTarget(client, client) 
                outputDebugString("Welcome to My Server.") 
            end 
        else 
            outputDebugString("Wrong password.") 
        end 
    else 
        outputDebugString("Wrong username.") 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",root,loginHandler) 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast

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