Jump to content

MySQL ... problem


Carbonik

Recommended Posts

Posted

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

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

Posted

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 
) 

Posted

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

Posted

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

Posted

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 
    ) 
  

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