scratcher911 Posted July 25, 2012 Share Posted July 25, 2012 function insertToMySQL() mysql_query(database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( Serial = '123', AccountName = 'Lala', Password = 'But' " ) end addEventHandler("onResourceStart", resourceRoot, insertToMySQL) It shows that at argument 1 is handler expected. Please don't fix the code for me just explain me what am I doing wrong¸ EDIT: function connectToMySQL() local database = mysql_connect( "127.0.0.1", "root", "", "XXXXX" ) if database then outputDebugString ('MySQL Service -- Connected') else outputDebugString ("MySQL Service -- Truble") end end addEventHandler("onResourceStart", resourceRoot, connectToMySQL) This is how I get Connection Link to comment
Castillo Posted July 25, 2012 Share Posted July 25, 2012 Well, it means that the MySQL handler is invalid. Link to comment
scratcher911 Posted July 25, 2012 Author Share Posted July 25, 2012 I've fixed that but now the insert does not work. Link to comment
Castillo Posted July 25, 2012 Share Posted July 25, 2012 Because is wrong. function insertToMySQL ( ) mysql_query ( database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( '123', 'Lala', 'But'" ) end addEventHandler ( "onResourceStart", resourceRoot, insertToMySQL ) Try with that. Link to comment
scratcher911 Posted July 25, 2012 Author Share Posted July 25, 2012 Still doesn't work. I've made the columns and all in PHPmyAdmin Link to comment
Castillo Posted July 25, 2012 Share Posted July 25, 2012 Try this: function insertToMySQL ( ) mysql_query ( database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( '123', 'Lala', 'But' );" ) end addEventHandler ( "onResourceStart", resourceRoot, insertToMySQL ) Link to comment
Castillo Posted July 25, 2012 Share Posted July 25, 2012 Well, I use it on that syntax, but I don't use Ryden's MySQL, I use MTA built-on functions. Link to comment
scratcher911 Posted July 25, 2012 Author Share Posted July 25, 2012 dbConnect ? I think it's a bit more easyer right ? EDIT: It's easier.. I've already make it. Thanks Solid Link to comment
Castillo Posted July 26, 2012 Share Posted July 26, 2012 Indeed, it's easier with MTA built-on functions. You're welcome. Link to comment
scratcher911 Posted July 26, 2012 Author Share Posted July 26, 2012 function setData(source) local x,y,z = getElementPosition(source) local r, g, b = getPlayerNametagColor( source ) local isData = dbQuery( database, "SELECT * FROM prsaver WHERE serial = "..getPlayerSerial(source).."" ) local result = dbPoll( isData, 0 ) if not result then local qh = dbQuery -- Long code here dbFree( qh ) end end problem is that it makes pass the result even if the serial is not in. Link to comment
Cadu12 Posted July 26, 2012 Share Posted July 26, 2012 What is your type? TEXT? VARCHAR? If it is TEXT or VARCHAR, try use: function setData ( source ) local x,y,z = getElementPosition ( source ) local r, g, b = getPlayerNametagColor ( source ) local isData = dbQuery ( database, "SELECT * FROM prsaver WHERE serial = '" .. getPlayerSerial ( source ) .. "'" ) local result = dbPoll ( isData, 0 ) if result and result ~= 0 then local qh = dbQuery -- Long code here dbFree ( qh ) end end Link to comment
Castillo Posted July 26, 2012 Share Posted July 26, 2012 function setData ( source ) local x, y, z = getElementPosition ( source ) local query = dbQuery ( database, "SELECT * FROM prsaver WHERE serial = '".. getPlayerSerial ( source ) .."' LIMIT 1" ) local result, numrows, errmsg = dbPoll ( query, 0 ) if ( not result ) or ( type ( result ) == "table" and #numrows == 0 ) then local r, g, b = getPlayerNametagColor ( source ) local qh = dbQuery -- Long code here dbFree ( qh ) end end That'll check if the result was not found. Link to comment
scratcher911 Posted July 26, 2012 Author Share Posted July 26, 2012 Cadu12 Your code doesn't eaven add the row. Solid It doesn't stop adding rows. Link to comment
Castillo Posted July 26, 2012 Share Posted July 26, 2012 Copy my code again and see if it works. Link to comment
scratcher911 Posted July 26, 2012 Author Share Posted July 26, 2012 Doesn't work. Forgot to mention that type for serial is TEXT Link to comment
Castillo Posted July 26, 2012 Share Posted July 26, 2012 You are sure that your column name is: "serial" and not "Serial"? Link to comment
sockz Posted July 26, 2012 Share Posted July 26, 2012 Try this: function insertToMySQL ( ) mysql_query ( database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( '123', 'Lala', 'But' );" ) end addEventHandler ( "onResourceStart", resourceRoot, insertToMySQL ) it doesn't work because 'INTRO' is supposed to be 'INTO'. INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3) how is this harder than mta sql functions? mysql_query (database, "INSERT INTO prresourcename (serial, accountname, password) VALUES (1, 2, 3)") Link to comment
Castillo Posted July 26, 2012 Share Posted July 26, 2012 Oh, I didn't see that typo . 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