SlashBuster Posted April 21, 2012 Share Posted April 21, 2012 Hi i have a problem How can I get for example the username and password that are from a editbox in the client script and put them as values in the dbExec command so that the text which is written in the box is postet into the database Link to comment
Michael# Posted April 21, 2012 Share Posted April 21, 2012 -- 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
SlashBuster Posted April 21, 2012 Author Share Posted April 21, 2012 and whatfor is the "?" Link to comment
Michael# Posted April 21, 2012 Share Posted April 21, 2012 ? = tostring ( text ) dbExec ( myConnection, "INSERT INTO `myTable` VALUES ( ? )", tostring ( text ) ) Link to comment
SlashBuster Posted April 21, 2012 Author Share Posted April 21, 2012 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
Michael# Posted April 21, 2012 Share Posted April 21, 2012 If you tell me what's you're doing... Link to comment
SlashBuster Posted April 21, 2012 Author Share Posted April 21, 2012 a login/register script Link to comment
Michael# Posted April 21, 2012 Share Posted April 21, 2012 And what is idUser, Name, Passwort, ... ?? Also, better start learning from something more easy. I gave you the correct code and you wrote a fucked up script. Link to comment
SlashBuster Posted April 21, 2012 Author Share Posted April 21, 2012 hmm these are the fields in the databank but I only want to know how I can wrote variables in the sql string Link to comment
Michael# Posted April 21, 2012 Share Posted April 21, 2012 ? = tostring ( text ) dbExec ( myConnection, "INSERT INTO `myTable` VALUES ( ? )", tostring ( text ) ) Link to comment
SlashBuster Posted April 21, 2012 Author Share Posted April 21, 2012 but what is the text? I Link to comment
SlashBuster Posted April 21, 2012 Author Share Posted April 21, 2012 tostring ( text ) I don't understand this string what is the text? Link to comment
Michael# Posted April 21, 2012 Share Posted April 21, 2012 -- 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
SlashBuster Posted April 21, 2012 Author Share Posted April 21, 2012 triggerServerEvent ( "submitRegister", getRootElement(), username, password, passwordConfirm ) yeah but i have it this way Link to comment
Michael# Posted April 21, 2012 Share Posted April 21, 2012 -- 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
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