kamani Posted February 21, 2010 Share Posted February 21, 2010 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 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
50p Posted February 21, 2010 Share Posted February 21, 2010 Why did you create new topic about the same subject? And saying "it's not working" doesn't tell us much. Tell us more. Link to comment
Aibo Posted February 21, 2010 Share Posted February 21, 2010 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. 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
kamani Posted February 21, 2010 Author Share Posted February 21, 2010 sorry for 2 meaningless topics, but i don't know how correct this login script. In game this command " /login [password] " worked bad, type /login password and anything wrong password. Link to comment
Aibo Posted February 21, 2010 Share Posted February 21, 2010 well, ok, when i think about it more, maybe you wanted it this way 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. EDIT: fixed your typo in paswd > passwd Link to comment
kamani Posted February 21, 2010 Author Share Posted February 21, 2010 Thanks (paswd>passwd), I saw himself. 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