Jump to content

Mysql


Recommended Posts

I've been trying to make a register system that uses the mysql module from the wiki but this code i have always gives me an error.

addEventHandler ( "onPlayerRegister", getRootElement(),  
    function(username, password) 
        local query = mysql_query(handler, "SELECT * FROM players WHERE username = "..username) 
        if (mysql_num_rows(query) == 0) then 
            mysql_query(handler, "INSERT INTO players (username, password) VALUES ('"..username.."',md5('"..password.."'))") 
        else 
            -- Account exists 
        end 
        mysql_free_result(query) 
    end) 

the error is: bad argument #1 to 'mysql_num_rows' (mysqlResult expected, got nil)

The table i'm querying is empty but that shouldn't affect what mysql_num_rows gets should it?

Link to comment
local query = mysql_query(handler, "SELECT * FROM players WHERE username = '"..username.."'") 

also escape username and password variables with mysql_escape_string() before putting them into the query string so you are protected against sql injection

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