Cadu12 Posted July 14, 2012 Share Posted July 14, 2012 Try use https://wiki.multitheftauto.com/wiki/Mod ... _fetch_row Should work Link to comment
Phoenix-Roleplay Posted July 14, 2012 Author Share Posted July 14, 2012 Alright, using that login works perfectly but still fails to retrieve the data (I presume..) function loginHandler(username,password) local result = mysql_query(handler, "SELECT * FROM accounts WHERE accname='" .. username .. "' AND accpassword='" .. password .. "'") local row = mysql_fetch_row(result) if(row)then outputChatBox("You have successfully logged in!", client, 0, 255, 0) setElementData(client, "logged", 1) setElementData(client, "account:admin", tonumber(row["admin"])) local AStatus = tonumber(row["admin"]) if (AStatus == 1) then outputChatBox("You are playing as a PR Moderator.", client, 0, 0, 255) elseif (AStatus == 2) then outputChatBox("You are playing as a PR Administrator.", client, 0, 0, 255) elseif (AStatus == 3) then outputChatBox("Welcome back, Phoenix.", client, 0, 0, 255) end outputChatBox(mysql_error(handler), client, 255, 0, 0) return true else outputChatBox("Your username and/or password is incorrect!", client, 255, 0, 0) triggerClientEvent(client, "displayLogin", getRootElement()) return false end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) Tried both variations on row["admin"] or row[1]["admin"] Link to comment
Cadu12 Posted July 14, 2012 Share Posted July 14, 2012 function loginHandler(username,password) local result = mysql_query(handler, "SELECT * FROM accounts WHERE accname='" .. username .. "' AND accpassword='" .. password .. "'") local row = mysql_fetch_assoc(result) if(result)then outputChatBox("You have successfully logged in!", client, 0, 255, 0) setElementData(client, "logged", 1) setElementData(client, "account:admin", tonumber(row["admin"])) local AStatus = tonumber(row["admin"]) if (AStatus == 1) then outputChatBox("You are playing as a PR Moderator.", client, 0, 0, 255) elseif (AStatus == 2) then outputChatBox("You are playing as a PR Administrator.", client, 0, 0, 255) elseif (AStatus == 3) then outputChatBox("Welcome back, Phoenix.", client, 0, 0, 255) end return true else outputChatBox("Your username and/or password is incorrect!", client, 255, 0, 0) triggerClientEvent(client, "displayLogin", getRootElement()) return false end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) Try my code, I tested in my localhost. Link to comment
Phoenix-Roleplay Posted July 15, 2012 Author Share Posted July 15, 2012 Interesting find, pasted the EXACT code and I get this ERROR: pf\s_main.lua:17: attempt to index local `row` (a nil value) EDIT: Upon further inspection, row["admin"] is failing to be set at all. Link to comment
Vision Posted July 15, 2012 Share Posted July 15, 2012 You need to create a table for 'row' row = {} Link to comment
Phoenix-Roleplay Posted July 15, 2012 Author Share Posted July 15, 2012 I'll try that but if I am not mistaken, the row = mysql_fetch_rows should do that for me? EDIT: Yea, same problem. Doesn't seem to withdraw the date from row["admin"] Link to comment
Cadu12 Posted July 15, 2012 Share Posted July 15, 2012 It worked for me, in my host. It's mysql_fetch_assoc Link to comment
Phoenix-Roleplay Posted July 15, 2012 Author Share Posted July 15, 2012 @Cadu, can you send me a SS of what it displays IG? EDIT: Wait, nevermind I got it fully functional now using the fetch_assoc! Thanks so much everyone, special thanks to Cadu! 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