StefanAlmighty Posted February 24, 2016 Share Posted February 24, 2016 Okay so I've reached an issue where in my script I have the following line: local preparedQuery3 = "INSERT INTO `accounts` (username, password, email, security_question, security_answer, last_serial, last_ip, salt) VALUES ('" .. toSQL(username) .. "', '" .. toSQL(encryptedPW) .. "', '" .. toSQL(email) .. "', 'nil', 'nil', '" .. mtaSerial .. "', '" .. toSQL(ipAddress) .. "', '" .. toSQL(encryptionRule) .. "')" When I click the 'register' button on my server, it gathers all the information and should create an account. However, I have to click the 'register' button like 4+ times in order for it to create an account, even though the query runs perfectly and says the account has been created. Link to comment
KariiiM Posted February 24, 2016 Share Posted February 24, 2016 Wrong usage, you have to use dbExec in this case. Link to comment
StefanAlmighty Posted February 24, 2016 Author Share Posted February 24, 2016 How come mysql_query works if it's clicked 4+ times, and it worked on a different script I used which is where I got the base idea from. Link to comment
KariiiM Posted February 24, 2016 Share Posted February 24, 2016 How come mysql_query works if it's clicked 4+ times, and it worked on a different script I used which is where I got the base idea from. I suggest you to stop using mysql moduls they are too old, use dbFunctions Link to comment
StefanAlmighty Posted February 24, 2016 Author Share Posted February 24, 2016 local Q3 = dbExec(mysql:connectMTA(), preparedQuery3) if Q3 then mysql:free_result(Q3) triggerClientEvent(source, "setLoginNotice", getRootElement(), "Successfully created account " .. username .. "!", 0, 255, 0) outputDebugString("DEBUG: " .. preparedQuery3) return true else mysql:free_result(Q3) triggerClientEvent(source, "setLoginNotice", getRootElement(), "Error creating account.", 255, 0, 0) return false end Doesn't work & dbExec returns false. Link to comment
KariiiM Posted February 24, 2016 Share Posted February 24, 2016 Did you even openned a connection to the database? Link to comment
StefanAlmighty Posted February 24, 2016 Author Share Posted February 24, 2016 Yes, it works with the MYSQL modules. Link to comment
Bonus Posted February 24, 2016 Share Posted February 24, 2016 Don't use free_result on a boolean (dbExec gives you boolean). Did you look into debugscript? And he is right, better use db functions. Link to comment
StefanAlmighty Posted February 24, 2016 Author Share Posted February 24, 2016 Got it working. However, it's causing the same issue but I know why. The encryption code I use for passwords is a 10 digit number. In the database the datatype for the column is: int(10). When I slowly broke down the query, it turned out to be the encryption code causing the issue - any suggestions? Link to comment
StefanAlmighty Posted February 24, 2016 Author Share Posted February 24, 2016 Nevermind! Turns out the encryption code was meant to be saved as an integer in the database, but the script was attempting to save it as a string. I fixed it by changing the datatype of the column to char(10) instead of int(10). Thanks for your help and from now on I will use database functions. 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