Jump to content

MySQL ... problem


Carbonik

Recommended Posts

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

Link to comment
  
      
    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.

Link to comment

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 
) 

Link to comment

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

Link to comment

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 
    ) 
  

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