Carbonik Posted November 5, 2012 Posted November 5, 2012 Hey Im beginner in SQL programming, I wanted to create simple table and insert data to it... table creates but somehow data can't. addEventHandler( "onResourceStart", resourceRoot, function( ) if not exports.mysql:create_table( 'characters', { { name = 'characterID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, { name = 'characterName', type = 'varchar(22)' }, } ) then cancelEvent( ) return end end) function testQueryFree(command, player) local result = exports.mysql:query_free("INSERT INTO characters (characterName) VALUES (John Smith)") if result then outputChatBox("You have succesfully inserted new character", player, 255, 255, 255) else outputChatBox("FAIL", player, 255, 255, 255) end end addCommandHandler("test", testQueryFree) Im not even getting fail... whats wrong with it
myonlake Posted November 5, 2012 Posted November 5, 2012 addEventHandler( "onResourceStart", resourceRoot, function( ) if not exports.mysql:create_table( 'characters', { { name = 'characterID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, { name = 'characterName', type = 'varchar(22)' }, } ) then cancelEvent( ) return end end) function testQueryFree(command, player) local result = exports.mysql:query_free("INSERT INTO characters (characterName) VALUES ('John Smith')") if result then outputChatBox("You have succesfully inserted new character", player, 255, 255, 255) else outputChatBox("FAIL", player, 255, 255, 255) end end addCommandHandler("test", testQueryFree) You forgot the upper dot, whatever it's called.
myonlake Posted November 5, 2012 Posted November 5, 2012 You also had the command handler's arguments wrongly defined. First comes the player, then the command. You had it the wrong way. Try this. addEventHandler("onResourceStart", resourceRoot, function() if not exports.mysql:create_table('characters', { { name = 'characterID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, { name = 'characterName', type = 'varchar(22)' }, }) then cancelEvent() return end end ) addCommandHandler("test", function(player, cmd) local result = exports.mysql:query_free("INSERT INTO characters (characterName) VALUES ('John Smith')") if result then outputChatBox("You have succesfully inserted new character", player, 0, 255, 0, false) else outputChatBox("FAIL", player, 255, 0, 0, false) end end )
Carbonik Posted November 5, 2012 Author Posted November 5, 2012 still doesn't work, I see nothing( and no errors in debug)
myonlake Posted November 6, 2012 Posted November 6, 2012 In that case you have no meta.xml, no resource, no correct file or haven't started the resource. You also have to make sure all this is server-side. Your command "test" should display either "FAIL" or "You have successfully...".
Carbonik Posted November 6, 2012 Author Posted November 6, 2012 It's all correct: login: You successfully logged in debugscript: Your debug mode was set to 3 start: Resource 'mysql_test' started meta.xml: <meta> <script src="server.lua" /> <include resource="mysql"/> </meta> no debug errors, when I type /test, nothing happens
fmj02 Posted November 6, 2012 Posted November 6, 2012 I have tested your resource, It didn't work, code was correct, I made folder "asdd" and created your meta and server: and it works check by yourself ;p have fun with scripting addEventHandler("onResourceStart", resourceRoot, function() if not exports.mysql:create_table('characters', { { name = 'characterID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, { name = 'characterName', type = 'varchar(22)' }, }) then cancelEvent() return end end ) addCommandHandler("makethiskrapidiot", function(player, cmd) local result = exports.mysql:query_free("INSERT INTO characters (characterName) VALUES ('John Smith')") if result then outputChatBox("You have succesfully inserted new character", player, 0, 255, 0, false) else outputChatBox("FAIL", player, 255, 0, 0, false) end end )
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