Jump to content

help with mysql error


kamani

Recommended Posts

hey, i have error

ERROR: mode/script.lua:11: bad argument #1 to 'mysql_query' (LuaBook.mysqlHandler expected, got nil)

this is my code:

sqllogin = mysql_connect("localhost", "root", "", "mta")
function joinHandler()
g_Red, g_Green, g_Blue = math.random (50, 255), math.random (50, 255), math.random (50, 255)
showPlayerHudComponent ( source, "radar", false )
fadeCamera(source, true, 5)
setCameraMatrix(source, -2727.537109375, 1259.0477294922, 21.859544754028, -2710.1669921875, 1447.4552001953, 62.596080780029)
givePlayerMoney ( source, 500 )
local username = getPlayerName(source)
local query = mysql_query(sqllogin, "SELECT * FROM users WHERE nick='" .. username .."'") --- this is ERROR LINE
if (mysql_num_rows(query) == 0) then
outputChatBox("please register!", source)
else
outputChatBox("please login!", source)
end
mysql_free_result(query)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

Link to comment

One question: Did you write the code in your first post yourself?

You can't just copy the parameter line from the wiki into your code.

This is just a syntax explanation, not real code for use.

You should have at least some knowledge, if you want to work with MySQL.

You have to look for your MySQL socket file on your server, this path will then be used as the "unix_socket" parameter.

I doubt that your MySQL port is changed, so port can be 3306.

Client flags can be left out, because that's just to enable special modes etc.

So it should look similar to this:

mysql_connect("localhost", "root", "", "mta",3306,"YOUR_SOCKET_PATH")

And now learn some Lua syntax.

https://wiki.multitheftauto.com/wiki/Scr ... troduction

http://www.lua.org/pil/index.html

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