Jump to content

Verify MYSQL


Recommended Posts

Hello, i'm trying to build a Roleplay gamemode from almost 0, I only have a MYSQL resource who exports functions

so, i have this code

mysql = exports.mysql
chat = outputChatBox
function greetPlayer (thePlayer )
	serial = getPlayerSerial(source)
	mysql:query_free("INSERT INTO serial SET seriala='" .. serial .. "'")
end
addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer )

how cand I verify if the serial is already in the SQL database? so that it cannot insert multiple times the same serial.

I've been looking online, and I see people using SELECT, but it's complicated and i want an explanation, so I cand understand.

Link to post
mysql = exports.mysql
chat = outputChatBox
addEventHandler ( "onPlayerJoin" , root , function ( ) 
local results = mysql:query_free ( "SELECT * FROM serial WHERE serial=?" , getPlayerSerial ( source ) ) ; 
if ( #results > 0 ) then 
mysql:query_free("INSERT INTO serial SET seriala='" ..getPlayerSerial(source).. "'")
end
end ) 

 

Link to post

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