Jump to content

[Help] Mysql Login


kamani

Recommended Posts

Hi all :) i created a login script ( using mysql module ) , But its wrong, i don't know what is wrong, but not working...

Help please :roll::roll:

Code:

function LoginSystem(source, commandName,pw)
local paswd = mysql_escape_string(sqllogin,pw) 
local nick = mysql_escape_string(sqllogin, getPlayerName(source))
local query = mysql_query(sqllogin, "SELECT * FROM users WHERE username='" .. nick .."' AND password='" .. passwd .. "'")
if (not query) then
outputDebugString("mysql_query failed: (" .. mysql_errno(sqllogin) .. ") " .. mysql_error(sqllogin)) 
else
if (mysql_num_rows(query) == 0) then 
end
outputChatBox("Wrong password", source) 
else
outputChatBox("Loged in", source) 
end
mysql_free_result(query) 
end
end
addCommandHandler("login", LoginSystem)

Link to comment

your if-else-ends are really messed up. i mean, function and 2 ifs means 3 ends and you have 4.

clear that up with indents, cause i can't really think of the way you wanted it to be. :S

function LoginSystem(source, commandName,pw)
local paswd = mysql_escape_string(sqllogin,pw)
local nick = mysql_escape_string(sqllogin, getPlayerName(source))
local query = mysql_query(sqllogin, "SELECT * FROM users WHERE username='" .. nick .."' AND password='" .. passwd .. "'")
if (not query) then
outputDebugString("mysql_query failed: (" .. mysql_errno(sqllogin) .. ") " .. mysql_error(sqllogin))
else
if (mysql_num_rows(query) == 0) then
-- then what?
end
outputChatBox("Wrong password", source)
-- and here it becomes broken with "else"
else
outputChatBox("Loged in", source)
end
   mysql_free_result(query)
end
end
addCommandHandler("login", LoginSystem)

Link to comment

well, ok, when i think about it more, maybe you wanted it this way :D

function LoginSystem(source, commandName,pw)
local passwd = mysql_escape_string(sqllogin,pw) -- paswd > passwd
local nick = mysql_escape_string(sqllogin, getPlayerName(source))
local query = mysql_query(sqllogin, "SELECT * FROM users WHERE username='" .. nick .."' AND password='" .. passwd .. "'")
if (not query) then
outputDebugString("mysql_query failed: (" .. mysql_errno(sqllogin) .. ") " .. mysql_error(sqllogin))
else
if (mysql_num_rows(query) == 0) then
outputChatBox("Wrong password", source)
else
outputChatBox("Loged in", source)
-- i hope you'll put some login routines here later
-- like setElementData or whatever
-- or else how you'll know that player is logged in?
end
   mysql_free_result(query)
end
end
addCommandHandler("login", LoginSystem)

as for login command, as i recall MTA package already includes authorization system and /login command is there already.

if you're making your own, don't forget to disable it.

and i think it's that login command that wasn't accepting your password, cause your code with that kind of error wouldn't even run.

though ofc i may be wrong. :D

EDIT: fixed your typo in paswd > passwd

Link to comment

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