FlyingSpoon Posted August 12, 2015 Share Posted August 12, 2015 function registerPlayer(username,password) handler = mysql_connect( host, username, password, db ) if not (username == "") then if not (password == "") then local account = getAccount (username,password) if (account == false) then local accountAdded = mysql_query(handler,"INSERT INTO accounts VALUES "(tostring(username),tostring(password))"';") if (accountAdded) then outputChatBox ("#FF0000* #00FF00You have sucessfuly registered! [username: #FFFFFF" .. username .. " #00FF00| Password: #FFFFFF" .. password .. "#00FF00 ]",source,255,255,255,true ) triggerClientEvent(source,"achievement:onRegister", getRootElement()) else outputChatBox("An error occured! Please choose a different username/or password!", source, 255, 0, 0) end else outputChatBox("An account with this username already exists!", source, 255, 0, 0) end else outputChatBox("Null!", source, 255, 0, 0) end else outputChatBox("Null!", source, 255, 0, 0) end end addEvent("onRequestRegister",true) addEventHandler("onRequestRegister",getRootElement(),registerPlayer) I am really stuck, I dont even know what's going on, please someone help me out! Thanks [2015-08-12 12:57:49] SCRIPT ERROR: login\s_login.lua:7: ')' expected near '(' [2015-08-12 12:57:49] ERROR: Loading script failed: login\s_login.lua:7: ')' expected near '(' Link to comment
FlyingSpoon Posted August 12, 2015 Author Share Posted August 12, 2015 Okay after finding more online resources, and other people's previous fixes.. I nearly got it working.. Now all it does it just keeps creating the same account over and over.. So.. how can I prevent this? function registrationHandler(username,password) handler = mysql_connect("localhost", "root", "", "roleplay") local row = mysql_query(handler, "SELECT * FROM accounts WHERE username=`"..username.."`") if row then outputDebugString("Username already exists") triggerClientEvent(client, "displayLogin", getRootElement()) return end local result = mysql_query(handler, "INSERT INTO accounts (username, password) VALUES ('"..username.."', '"..password.."')") if not result then outputDebugString("Registration failed. "..mysql_error(handler)) triggerClientEvent(client, "displayLogin", getRootElement()) return end triggerClientEvent(client, "displayLogin", getRootElement()) outputChatBox("Registration successful!", client, 0, 255, 0) end addEvent("onRequestRegister",true) addEventHandler("onRequestRegister",root,registrationHandler) Link to comment
GTX Posted August 13, 2015 Share Posted August 13, 2015 1. Don't connect to MySQL database every time you register. 2. Free the query result (mysql_free_result) 3. MySQL module is outdated and deprecated. Use DB 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