Jump to content

MTA SQL


StefanAlmighty

Recommended Posts

Posted

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.

Posted
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

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

Posted

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.

Posted

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?

Posted

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.

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