CourtezBoi Posted December 8, 2011 Share Posted December 8, 2011 Hello there. I'm creating an account system for my mta server, and I've completely finished except one line of code that refuses to cooperate. The below function is called from a client-side script, sending it the name, description, age and skin of a players new character that they're trying to create, and this functions job is to send that information to the database and essentially create the character. function createCharacter ( name, desc, age, skin ) player = source if ( type ( name ) == "string" ) and age and skin and desc then local account = getAccountID ( player ) if account then local x, y, z = 1480, -1744, 14 local rotation, interior, dimension = 0, 0, 0 local money = 750 local char, error = exports.sql:query_insertid("INSERT INTO characters (account, character, x, y, z, rotation, interior, dimension, skin, money, age, desc) VALUES ("..table.concat( { account, name, x, y, z, rotation, interior, dimension, skin, money, age, desc }, ", ")..")") if char then outputChatBox ( "DEBUG: QUERY SUBMITTED" ) outputChatBox ( name:gsub ( " ", "_" ).." "..age.." "..skin.." "..desc.." "..tostring ( char ) ) setPlayerName ( player, name:gsub ( " ", "_" ) ) outputChatBox ( "You are now playing as "..name:gsub("_", " ")..".", player, 155, 255, 155 ) spawnPlayer ( player, x, y, z, rotation, skin, interior, dimension ) loadCharacters ( player ) setCharacterID ( player, char ) else outputChatBox ( "DEBUG: QUERY FAILED" ) outputChatBox ( "ERROR: "..error, player, 255, 155, 155 ) end else outputChatBox ( "You must be logged in to continue.", player, 255, 155, 155 ) end else outputChatBox ( "An error has occured, please report this issue on the bugtracker.", player, 255, 155, 155 ) end end The problem is the query itself. local char, error = exports.sql:query_insertid("INSERT INTO characters (account, character, x, y, z, rotation, interior, dimension, skin, money, age, desc) VALUES ("..table.concat( { account, name, x, y, z, rotation, interior, dimension, skin, money, age, desc }, ", ")..")") For some reason, this refuses to query. In the above if statement, it always goes false, and outputs the DEBUG: QUERY FAILED but the error variable is still nil so the next line doesn't send. My question is simply, why does it not submit this query. I've looked at my vehicle system which uses a similar query, and it inserts perfectly fine! Thanks in advance to anybody who can help. Link to comment
CourtezBoi Posted December 8, 2011 Author Share Posted December 8, 2011 Figured it out myself, was some weird syntax error that SQL didn't feel like telling me about. Here is the final code, in case it can help somebody else. local char, error = exports.sql:query_insertid("INSERT INTO characters (`account`, `character`, `x`, `y`, `z`, `rotation`, `interior`, `dimension`, `skin`, `money`, `age`, `desc`) VALUES ("..'"'..table.concat( { account, name, x, y, z, rotation, interior, dimension, skin, money, age, desc }, '", "')..'")') Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now