Jump to content

MySQL Get values


Recommended Posts

-- client 
  
myEdit = guiCreateEdit ( ... ) 
myButt = guiCreateButton ( ... ) 
  
addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if ( source == myButt ) then 
            triggerServerEvent ( 'updateDb', root, guiGetText ( myEdit ) ) 
        end 
    end 
) 
  
-- server 
  
local myConnection = dbConnect ( "mysql", "dbname=example;host=localhost", "***", "***", "share=1" ) 
  
addEvent ( 'updateDb', true ) 
addEventHandler ( 'updateDb', root, 
    function ( text ) 
        local add = dbExec ( myConnection, "INSERT INTO `myTable` VALUES ( ? )", tostring ( text ) ) 
    end 
) 

?

Link to comment

and the text comes from where? on client side I already have a script that takes the data that is post in the edit box to the server script

  
function registerHandler(username,password) 
     
  
    DB_connect = dbConnect("mysql", "dbname=mta_userdata;host=127.0.0.1","root","klaas","share=1") 
  
    Register = dbExec(DB_connect,"INSERT INTO `user` (`idUser`, `Name`, `Passwort`) VALUES ('', 'Value', 'Value2')") 
     
  
  
  
  
end 
addEvent("submitRegister", true) 
addEventHandler("submitRegister",getRootElement(),registerHandler) 

Link to comment
-- client 
  
myEdit = guiCreateEdit ( ... ) 
myButt = guiCreateButton ( ... ) 
  
addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if ( source == myButt ) then 
            triggerServerEvent ( 'updateDb', root, guiGetText ( myEdit ) ) -- tostring ( text ) -> guiGetText ( myEdit ) 
        end 
    end 
) 
  
-- server 
  
local myConnection = dbConnect ( "mysql", "dbname=example;host=localhost", "***", "***", "share=1" ) 
  
addEvent ( 'updateDb', true ) 
addEventHandler ( 'updateDb', root, 
    function ( text ) -- text -> guiGetText ( myEdit ) 
        local add = dbExec ( myConnection, "INSERT INTO `myTable` VALUES ( ? )", tostring ( text ) ) 
    end 
) 

?

Read comments.

Link to comment
-- client side 
  
triggerServerEvent ( "submitRegister", getRootElement(), username, password, passwordConfirm ) -- send data 
  
-- server side 
  
function registerHandler(username,password,passwordConfirm)  
    if ( password == passwordConfirm ) then -- if pw is equal to confirmation 
      local connect = dbConnect("mysql", "dbname=mta_userdata;host=127.0.0.1","root","klaas","share=1") -- connect to db 
        if ( connect ) then -- if connected sucessfully 
           dbExec(connect,"INSERT INTO `user` VALUES ( ?, ?, ? )", tostring ( username ), tostring ( password ), tostring ( passwordConfirm ) ) -- insert data 
        else 
            return -- if not connected sucessfully, end function 
        end 
    else 
        return -- if password is not the same of confirm, end function 
    end 
end 
addEvent("submitRegister", true) 
addEventHandler("submitRegister",getRootElement(),registerHandler) 

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