Jump to content

Table doesn't exist


FSXTim

Recommended Posts

Posted (edited)

Hello,

I have a small problem again.

DebugString: Unknown 'Name' in 'where clause'.

And also the DebugString doesn't say 'Test'.

First script:

function bann (nick, ip, username, serial) 
    local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") 
    if bt then 
        bool = not (bt == 0) 
    end 
    if bool then 
        if bt > 0 then 
            outputDebugString("Test") 
            cancelEvent(true, "Du bist gebannt!") 
        end 
    end 
end 
addEventHandler("onPlayerConnect", getRootElement(), bann) 

Second script:

function MySQL_GetString(feldN, tableN, bedingung) 
    local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE "..bedingung) 
    if (not result) then 
         outputDebugString(mysql_error(sqlcon))  
    else 
        if(mysql_num_rows(result) > 0) then 
            local ds = mysql_fetch_assoc(result) 
            local savename = feldname 
            mysql_free_result(result) 
            return ds[feldname] 
        else 
            mysql_free_result(result) 
            return false 
        end 
    end 
end 

Greets

Edited by Guest
Posted

Everything seems to be fine for me. Either the table does not exist or you have selected a wrong database. Without a screenshot of the MySQL structure and the LUA code where the connection info is stored we can not help you much.

Posted

It's working now. Sorry, it was my mistake.

But no I have another problem.

DebugString: Unknown 'Name' in 'where clause'.

And also the DebugString doesn't say 'Test'.

First script:

function bann (nick, ip, username, serial) 
    local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") 
    if bt then 
        bool = not (bt == 0) 
    end 
    if bool then 
        if bt > 0 then 
            outputDebugString("Test") 
            cancelEvent(true, "Du bist gebannt!") 
        end 
    end 
end 
addEventHandler("onPlayerConnect", getRootElement(), bann) 

Second script:

function MySQL_GetString(feldN, tableN, bedingung) 
    local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE "..bedingung) 
    if (not result) then 
         outputDebugString(mysql_error(sqlcon))  
    else 
        if(mysql_num_rows(result) > 0) then 
            local ds = mysql_fetch_assoc(result) 
            local savename = feldname 
            mysql_free_result(result) 
            return ds[feldname] 
        else 
            mysql_free_result(result) 
            return false 
        end 
    end 
end 

Greets

Posted

That's because is wrong syntax.

local result = mysql_query(sqlcon, "SELECT ".. feldN .." FROM ".. tableN .." WHERE columnName = ".. bedingung .."") 

Posted

Thanks, Solidsnake14, but I had to change it to:

function MySQL_GetString(feldN, tableN, bedingung) 
    local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, username).."';") 
    if (not result) then 
         outputDebugString(mysql_error(sqlcon))  
    else 
        if(mysql_num_rows(result) > 0) then 
            local ds = mysql_fetch_assoc(result) 
            local savename = feldname 
            mysql_free_result(result) 
            return ds[feldname] 
        else 
            mysql_free_result(result) 
            return false 
        end 
    end 
end 

Error: Bad argument #2 'mysql_escape_string' (string expected, got nil)

Greets

Posted
function MySQL_GetString(feldN, tableN, bedingung) 
    local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") -- Your argument is: "bedingung", not "username". 
    if (not result) then 
         outputDebugString(mysql_error(sqlcon)) 
    else 
        if(mysql_num_rows(result) > 0) then 
            local ds = mysql_fetch_assoc(result) 
            local savename = feldname 
            mysql_free_result(result) 
            return ds[feldname] 
        else 
            mysql_free_result(result) 
            return false 
        end 
    end 
end 

Read comment.

Posted

Thanks, no more errors in the second script.

But I have one problem, the DebugString doesn't say 'Test' and the event isn't canceled.

Error (line 3): attempt to compare number with boolean

function bannCheck (nick, ip, username, serial) 
    local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") 
        if bt > 0 then 
            outputDebugString("Test") 
            cancelEvent(true, "Du bist gebannt!") 
        end 
    end 
end 
addEventHandler("onPlayerConnect", getRootElement(), bannCheck) 

Greets

Posted
function MySQL_GetString(feldN, tableN, bedingung) 
    local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") 
    if (not result) then 
         outputDebugString(mysql_error(sqlcon)) 
    else 
        if(mysql_num_rows(result) > 0) then 
            local ds = mysql_fetch_assoc(result) 
            local savename = feldname 
            mysql_free_result(result) 
            return ds[feldname] 
        else 
            mysql_free_result(result) 
            return false 
        end 
    end 
end 

Greets

Posted

What do you mean? What do I have to change?

I think I found the problem.

The DebugString sais 'Test', indifferent what 'Bann' is. It can be 0, 5 or 10 (line 13).

The DebugString sais '0', although 'Bann' is '15' (line 6).

function MySQL_GetString(feldN, tableN, bedingung) 
    local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") 
    if (not result) then 
         outputDebugString(mysql_error(sqlcon)) 
    else 
        outputDebugString(mysql_num_rows(result)) 
        if(mysql_num_rows(result) > 0) then 
            local ds = mysql_fetch_assoc(result) 
            local savename = feldN 
            mysql_free_result(result) 
            return ds[feldN] 
        else 
            outputDebugString("Test!")       
            mysql_free_result(result) 
            return false 
        end 
    end 
end 

What do I have to do to fix it?

Greets

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