Jump to content

mysql_num_rows; mysqlResult expected, got nil


Solstice.

Recommended Posts

Finally fixed my MySQL database. For some reason line 24 returns nil despite the username and password are both present within the database.

function login_seq (username, password) 
    handler = mysql_connect("SOMEHOST", "SOMEUSER", "SOMEPASS", "SOMEDB", 3306) 
    if handler then 
    safeusername = mysql_escape_string(handler, username) 
    safepassword = mysql_escape_string(handler, password) 
    accountCheck = "SELECT 'account_name','account_password' FROM 'account_info' WHERE 'account_name'='"..safeusername.."' AND 'account_password'='"..safepassword.."'" 
        if (string.len(username)<3) then 
            outputChatBox ( "Username needs to be longer than 3 characters.", 255, 0, 0) 
            triggerClientEvent("clearlogingui", getRootElement()) 
            mysql_close ( handler ) 
        end 
        local details = mysql_query(handler, accountCheck) 
        if (mysql_num_rows(details) > 0) then 
            outputChatBox ( ""..safeusername.. "") 
            spawnPlayer (client, 1687.7318115234, 1448.0688476563, 10.768267631531, -90, 0, 0) -- spawn the player 
            setCameraTarget (client, client) -- fixate the camera on the player target 
            setElementDimension ( getRootElement(), 0 ) -- spawn the player in the world's standard dimension 
            triggerClientEvent ("onloginsucces", getRootElement()) 
            mysql_close ( handler ) 
        else 
            outputChatBox ( "The username/password combination does not exist.", 255, 0, 0 ) 
            triggerClientEvent("clearlogingui", getRootElement()) 
            mysql_close ( handler ) 
        end 
    end 
end 
  
addEvent ("onLogin", true) -- creates a remote-triggered event linking the client-side script to the server-side login parameters 
addEventHandler ("onLogin", root, login_seq) -- starts the login sequence function upon the client-side script being triggered is true 

1Bxui

Link to comment

the mysqlResult object becomes nil when there's a syntax error in your script

your syntax error is here:

  
SELECT 'account_name','account_password'  
/* --> */ FROM 'account_info' /* <-- */  
WHERE 'account_name'='"..safeusername.."'  
AND 'account_password'='"..safepassword.."' 

because youre executing the query not on a table or an array, but on a string

and while that is an actual syntax error, this error wont get caught: all of your stuff that refers to cells and so are parsed as strings, so only in the even you would use account_name as a username and account_password as the password it would return one row, and the values would be account_name and account_password

accountCheck =  "SELECT account_name,account_password FROM account_info WHERE account_name='"..safeusername.."' AND account_password='"..safepassword.."'" 

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