Jump to content

Saving data into MySQL problem


..:D&G:..

Recommended Posts

Hey guys, I tried to make a function that lets players drop items for the gamemode I am using. I want the data of the dropped item to be saved into a MySQL database, but it doesn't save:

if drop then 
                    setElementData ( drop, "id", id ) 
                    setElementData ( drop, "value", value ) 
                    setElementData ( drop, "name", name ) 
                    setElementInterior ( drop, int ) 
                    setElementDimension ( drop, dim ) 
                    take( source, slot ) 
                    local posx, posy, posz = getElementPosition ( drop ) 
                    local index, error = exports.sql:query_insertid( "INSERT INTO dropitems (id, value, name, posx, posy, posz, int, dim) VALUES (" .. id .. ", " .. value .. ", " .. name .. ", " .. posx .. ", " .. posy .. ", " .. posz .. ", " .. int .. ", " .. dim .. ")")   
                        if index then 
                        -- add at the last position as a new item 
                        exports.chat:me( source, "drops a " .. name .. "." ) 
                        table.insert( data[ drop ].items, { id = id, value = value, name = name, posx = posx, posy = posy, posz = posz, int = int, dim = dim } ) 
                        -- tell everyone who wants to know 
                        notify( drop ) 
                        return true 
                        end  
                    end 

The "notify" bit, tells me if the content of the mysql table has been changed, when I added an item manualy in the table, it told me that new data has been added...

Any ideas guys?

Link to comment

If the int is an actual int, and the database table reflects that, then it should not be within quotes. That would be throwing errors. But considering your naming conventions, that's probably not the case. If they are all set as varchars then I don't see any problems with the SQL, without some errors to go on, and especially without verifying the "notify" function is created properly, it's hard to say.

It may be worth trying to change "int" to something else, as it may be protected and causing errors, but that's just a long shot guess, I don't know if it would apply to LUA.

Link to comment

This is what I did:

local drop = createObject ( obj, x+math.sin(math.rad(-ang)), y+math.cos(math.rad(-ang)), z - 0.85, 90, 0, math.random (0, 360) ) 
                    if drop then 
                    setElementData ( drop, "id", id ) 
                    setElementData ( drop, "value", value ) 
                    setElementData ( drop, "name", name ) 
                    setElementInterior ( drop, interior ) 
                    setElementDimension ( drop, dimension ) 
                    take( source, slot ) 
                    local posx, posy, posz = getElementPosition ( drop ) 
                    local index, error = exports.sql:query_insertid( "INSERT INTO dropitems (id, value, name, posx, posy, posz, interior, dimension) VALUES (" .. id .. ", " .. value .. ", " .. name .. ", " .. posx .. ", " .. posy .. ", " .. posz .. ", " .. interior .. ", " .. dimension .. ")")   
                        if index then 
                        -- add at the last position as a new item 
                        exports.chat:me( source, "drops a " .. name .. "." ) 
                        table.insert( data[ drop ].items, { id = id, value = value, name = name, posx = posx, posy = posy, posz = posz, interior = interior, dimension = dimension } ) 
                        -- tell everyone who wants to know 
                        notify( drop ) 
                        return true 
                        end  
                    end 
                    outputChatBox( "This " ..name.. " has ID " .. slot .. ".", source, 0, 255, 0 ) 
                end 
            end 
        end 
    end 
) 

I changed the columns from int and dim to interior and dimension, and also setted the interior column to tinyint and dimension to an int but still it doesn't add the data to the table

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