Jump to content

MySQL Error


Gtagasje

Recommended Posts

Hello there,

Once again, something is bugging me. And once again, it's mysql. I have made a function which adds something to the table, and then right after that checks for a value in that table, since 1 of the columns is auto increment.

I guess my function would explain it better:

  
function createHouse(x, y, z, interior, intx, inty, intz, price) 
    local handler = dbQuery(connection, "INSERT INTO Houses(X, Y, Z, Interior, IntX, IntY, IntZ, Locked, Passworded, Password, Price, Sale, Owner) VALUES(?,?,?,?,?,?,?,'No','No','',?,'No','')", x, y, z, interior, intx, inty, intz, price) 
    local res = dbPoll(handler, -1) 
    if res then 
        local resid = dbPoll(dbQuery(connection, "SELECT * FROM Houses WHERE X=? AND Y=? AND Z=? AND Interior=? AND IntX=? AND IntY=? AND IntZ=? AND Price=?", x, y, z, interior, intx, inty, intz, price), -1) 
  
        outputChatBox("House "..(resid.ID).." has been created successfully!", source, 0, 255, 0) -- Error line 
        buildHouse(id, x, y, z, interior, intx, inty, intz, price) 
    else 
        outputChatBox("An error occured while creating the house!", source, 255, 0, 0) 
    end 
end 
addEvent("createHouse", true) 
addEventHandler("createHouse", getRootElement(), createHouse) 
  

Now the error I'm getting is as following: attempt to concatenate field 'ID' (a nil value)

This is getting caused at the line of the outputChatBox().

I have tried delaying the selecting with 1 second, but that gave the same error. So I do not think the database being slow is the problem.

So, I really have no clue what is causing this error, and as you can maybe tell I am yet to be an expert at mysql.

Thanks in advance,

Gtagasje.

Link to comment

Hmm, not sure why I did it. I guess I'll change that too then (too bad I'm still on my phone.)

Also, on a side note, why is it better to use dbExec for insert queries? Because when I looked at the database, it inserted it perfectly fine, and I'm kinda curious now.

Link to comment

Okay, so, now I've changed the things you pointed out, and I have this:

  
function createHouse(x, y, z, interior, intx, inty, intz, price) 
    local handler = dbExec(connection, "INSERT INTO Houses(X, Y, Z, Interior, IntX, IntY, IntZ, Locked, Passworded, Password, Price, Sale, Owner) VALUES(?,?,?,?,?,?,?,'No','No','',?,'No','')", x, y, z, interior, intx, inty, intz, price) 
    if handler then 
        local resid = dbPoll(dbQuery(connection, "SELECT * FROM Houses WHERE X=? AND Y=? AND Z=? AND Interior=? AND IntX=? AND IntY=? AND IntZ=? AND Price=?", x, y, z, interior, intx, inty, intz, price), -1) 
  
        outputChatBox("House "..(resid[1].ID).." has been created successfully!", source, 0, 255, 0) 
        buildHouse(id, x, y, z, interior, intx, inty, intz, price) 
    else 
        outputChatBox("An error occured while creating the house!", source, 255, 0, 0) 
        dbFree(resid) 
    end 
end 
addEvent("createHouse", true) 
addEventHandler("createHouse", getRootElement(), createHouse) 
  

Yet, now I get this error(on the outputChatBox() line again.):

ERROR: Attempt to index field '?'(a nil value) 

Any ideas on what's the problem?

Link to comment

Yup, the data was being inserted, but when I wanted to go and take a screenshot I saw what was wrong. Appearently the database rounded the x y and z to 0 decimals, so the check I did afterwards obviously didn't exist, because that had like 10 decimals. So thank you for making me check that.

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