FlyingSpoon Posted April 21, 2015 Share Posted April 21, 2015 CLIENT SIDE function saveBusiness() if source == btnCreateBus then local getBusName = guiGetText ( edName ) if getBusName then triggerServerEvent("onBusinessCreate", getLocalPlayer(), getBusName) end end end addEventHandler("onClientGUIClick", resourceRoot, saveBusiness) SERVER SIDE mysql = exports.mysql function createBusiness(getBusName) mysql:query_free("INSERT INTO business (name)", getBusName) outputChatBox("Congratulations, you have created your business", source, 255, 194, 14) end addEvent("onBusinessCreate", true) addEventHandler("onBusinessCreate", getRootElement(), createBusiness) It outputs no errors? Any help would be appreciated, as I can then continue learning MySQL! Link to comment
..:D&G:.. Posted April 21, 2015 Share Posted April 21, 2015 mysql = exports.mysql function createBusiness(name) local insert = mysql:query_free("INSERT INTO business SET name=".. mysql:escape_string(name) .."") if (insert) then outputChatBox("Congratulations, you have created your business", source, 255, 194, 14) else outputDebugString("Mysql Error: Unable to create business!") mysql:free_result(insert) end end addEvent("onBusinessCreate", true) addEventHandler("onBusinessCreate", getRootElement(), createBusiness) Link to comment
FlyingSpoon Posted April 21, 2015 Author Share Posted April 21, 2015 Huh? Doesnt work, and what about the other getBusName? Link to comment
..:D&G:.. Posted April 21, 2015 Share Posted April 21, 2015 Well first check what's the name of the collumn of your MySQL database where the name of the business goes and change "name" to the name of the collumn. Also, getBusName is just a name for the function arguments, so it doesn't matter how you name it in the function and trigger if they are in the same order. EG: If in server side you have "function testFunction (thePlayer, argument1, argument2)" and in client you trigger something like this "triggerServerEvent ( "testFunction", thePlayer, arg1, arg2 )" then what you have for arg1 and arg2 will output in argument1 and argument2... I'm not really good at explaining Link to comment
FlyingSpoon Posted April 21, 2015 Author Share Posted April 21, 2015 mysql = dbConnect( "mysql", "dbname=thedb;host=localhost", "root", "", "share=1" ) function createBusiness(getBusName) local insert = dbExec( mysql, "INSERT INTO business VALUES (name)", getBusName ) if (insert) then outputChatBox("Congratulations, you have created your business", source, 255, 194, 14) else outputDebugString("MySQL Error: Unable to create business!") end end addEvent("onBusinessCreate", true) addEventHandler("onBusinessCreate", getRootElement(), createBusiness) What if I was to do this? It still outputs no error Link to comment
..:D&G:.. Posted April 21, 2015 Share Posted April 21, 2015 I am not really good with SQLite, my code should work if you have a roleplay mysql resource... Link to comment
xXMADEXx Posted April 22, 2015 Share Posted April 22, 2015 Try this: local mysql = exports.mysql function createBusiness(getBusName) mysql:query_free("INSERT INTO business ( 'name' ) VALUES ( ? )", getBusName) outputChatBox("Congratulations, you have created your business", source, 255, 194, 14) end addEvent("onBusinessCreate", true) addEventHandler("onBusinessCreate", getRootElement(), createBusiness) If that doesn't work, try using this: local mysql = exports.mysql function createBusiness(getBusName) mysql:query_free("INSERT INTO business ( 'name' ) VALUES ( '".. getBusName .." )" ) outputChatBox("Congratulations, you have created your business", source, 255, 194, 14) end addEvent("onBusinessCreate", true) addEventHandler("onBusinessCreate", getRootElement(), createBusiness) However in the second one, unless the query_free function filters the query, sql injection will be possible. If the first one doesn't work, please post the query_free function. Link to comment
FlyingSpoon Posted April 22, 2015 Author Share Posted April 22, 2015 mysql_query(mysql, "INSERT INTO business ( 'name' ) VALUES ( '".. getBusName .." )" ) I even tried this, still nothing Link to comment
ALw7sH Posted April 22, 2015 Share Posted April 22, 2015 mysql = dbConnect( "mysql", "dbname=thedb;host=localhost", "root", "", "share=1" ) function createBusiness(getBusName) local insert = dbExec( mysql, "INSERT INTO business ( name ) VALUES ( ? )", getBusName ) if (insert) then outputChatBox("Congratulations, you have created your business", source, 255, 194, 14) else outputDebugString("MySQL Error: Unable to create business!") end end addEvent("onBusinessCreate", true) addEventHandler("onBusinessCreate", getRootElement(), createBusiness) be sure that the sql is connected Link to comment
WhoAmI Posted April 22, 2015 Share Posted April 22, 2015 Check if table exist in database. Link to comment
FlyingSpoon Posted April 22, 2015 Author Share Posted April 22, 2015 It exists, Also no outputs, outputted! @ALw7sH Link to comment
xXMADEXx Posted April 22, 2015 Share Posted April 22, 2015 It exists,Also no outputs, outputted! @ALw7sH If there's no output, then are you sure that the onBusinessCreate event is even being triggered? Link to comment
FlyingSpoon Posted April 23, 2015 Author Share Posted April 23, 2015 Yep! The GUI and everything appears! Link to comment
ALw7sH Posted April 23, 2015 Share Posted April 23, 2015 How you can be sure that the event triggred if there's no errors or anything outputted put outputDebugString at the first line of the "createBusiness" function to be sure that it's beeing triggred mysql = dbConnect( "mysql", "dbname=thedb;host=localhost", "root", "", "share=1" ) function createBusiness(getBusName) outputDebugString("onBusinessCreate Has been triggred !") local insert = dbExec( mysql, "INSERT INTO business ( name ) VALUES ( ? )", getBusName ) if (insert) then outputChatBox("Congratulations, you have created your business", source, 255, 194, 14) else outputDebugString("MySQL Error: Unable to create business!") end end addEvent("onBusinessCreate", true) addEventHandler("onBusinessCreate", getRootElement(), createBusiness) 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