TheCouncil Posted June 19, 2014 Posted June 19, 2014 Hey Guys,I've Been Making a Login Panel with mysql i made a register command first to see if it's working,it worked good with "INSERT" but when i tried to login it doesn't want to login,so can anyone help me please?it doesn't give me any errors here the serverside code function LoginPlayer(playerSource, commandName, _password) handler = dbConnect("mysql","dbname=DBNAME;host=127.0.0.1","root","") local name = getPlayerName(playerSource) -- Escape the strings to avoid SQL-Injection local password = _password local query = " SELECT * FROM smf_players WHERE username='" .. name .. "' AND password='" .. md5(password) .. "'" if (dbQuery(handler, query)) then local rows = dbPoll(dbQuery(handler, query),-1) if rows == 1 then outputChatBox("You Succefully Logged In.", playerSource) else outputChatBox("An error has occured when trying to login", playerSource) end end end addCommandHandler("loginn", LoginPlayer)
Castillo Posted June 19, 2014 Posted June 19, 2014 First, you shouldn't connect everytime someone tries to login, you should connect only once, and use the handler in the query later.
TheCouncil Posted June 19, 2014 Author Posted June 19, 2014 you mean like that? handler = dbConnect("mysql","dbname=DBNAME;host=127.0.0.1","root","") function LoginPlayer(playerSource, commandName, _password) local name = getPlayerName(playerSource) -- Escape the strings to avoid SQL-Injection local password = _password local query = " SELECT * FROM smf_players WHERE username='" .. name .. "' AND password='" .. md5(password) .. "'" if (dbQuery(handler, query)) then local rows = dbPoll(dbQuery(handler, query),-1) if rows == 1 then outputChatBox("You Succefully Logged In.", playerSource) else outputChatBox("An error has occured when trying to login", playerSource) end end end addCommandHandler("loginn", LoginPlayer)
Castillo Posted June 20, 2014 Posted June 20, 2014 handler = dbConnect ( "mysql", "dbname=DBNAME;host=127.0.0.1", "root", "" ) function LoginPlayer ( playerSource, commandName, _password ) local name = getPlayerName ( playerSource ) -- Escape the strings to avoid SQL-Injection local query = dbQuery ( handler, "SELECT * FROM smf_players WHERE username = ? AND password = ?", name, md5 ( _password ) ) if ( query ) then local result, rows = dbPoll ( query, -1 ) if ( rows == 1 ) then outputChatBox ( "You Succefully Logged In.", playerSource ) else outputChatBox ( "An error has occured when trying to login", playerSource ) end end end addCommandHandler ( "loginn", LoginPlayer )
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