Jump to content

problem with dbQuery checking if value exists


Recommended Posts

I have a problem

function existsBetaKey (key) 
    local query = dbQuery ( handler, "SELECT * FROM betakeys WHERE Key=?",key ) 
        result , numrows, errmsg = dbPoll (query, -1) 
            local row = result[1] 
                if row then 
                    return true 
                else 
                    return false 
                end 
end 

db.log error:

2013-07-20 16:06:46.840: [script] FAIL: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Key ='8201-2349-3772-3253'' at line 1 [Query:SELECT * FROM betakeys WHERE Key ='8201-2349-3772-3253'] 

console error:

[2013-07-20 16:06:46] WARNING: prox\beta\beta_s.lua:37: dbPoll failed; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Key ='8201-2349-3772-3253'' at line 1 
[2013-07-20 16:06:46] ERROR: prox\beta\beta_s.lua:38: attempt to index global 'result' (a boolean value) 

db:

error2.JPG

Edited by Guest
Link to comment

I don't see any problem in your code, I don't think that the problem will be fixed with this code but you can always try:

  
function existsBetaKey (key) 
    local query = dbQuery ( handler, "SELECT * FROM betakeys WHERE Key = ?", tostring(key)) 
    result , numrows, errmsg = dbPoll (query, -1) 
            local row = result[1] 
                if row then 
                    return true 
                else 
                    return false 
                end 
end 
  

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