Jump to content

MySQL problem.


Michcio

Recommended Posts

Debug outputs: "ERROR: nowy_system\konta_s.lua:4: attempt to get length of local 'result' (a boolean value)"

function zarejestruj (plr,cmd,login,haslo) 
if login ~= nil and haslo ~= nil then 
local result = exports.sql:query_assoc( "SELECT login FROM konta WHERE login = "..login ) 
if (#result == 0) then 
    local insertid,e = exports.sql:query_insertid( "INSERT INTO konta ( kasa, score ) VALUES (" .. table.concat( { 5000, 0 }, ", " ) .. ")" ) 
    if insertid then 
        exports.sql:query_free( "UPDATE konta SET login = '"..login.."' WHERE ID = "..insertid ) 
        exports.sql:query_free( "UPDATE konta SET haslo = '"..md5(haslo).."' WHERE ID = "..insertid ) 
        outputChatBox( "Konto zarejestrowane. (ID: " .. insertid .. ")",plr,255,255,0 ) 
    else 
        outputDebugString( e ) 
        outputChatBox( "Blad bazy MySQL.", player, 255, 0, 0 ) 
    end 
else 
outputChatBox( "Taki login juz istnieje!",plr,255,255,0 ) 
end 
end 
end 
addCommandHandler("zarejestruj",zarejestruj) 

Link to comment

So, line 4 should be:

if result and #result == 0 then

Something else: your MySQL is wrong. login and haslo arguments are strings. If you put it in the query, you need to add ' ' around the string. In a MySQL query, all string-values must be between ' '. I guess login is an username, for example "Puma", so then it should be 'Puma' in the MySQL query and not Puma (without ' '). Numbers do not need ' '.

So this:

"SELECT login FROM konta WHERE login = "..login 

Should be this:

"SELECT login FROM konta WHERE login = '"..login.."'" 

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