Jump to content

[OK] set&getElementData and MySQL


Recommended Posts

Hi all

I explain my situation. I'm creating an userpanel with MySQL Database.

Step By Step

1. When the player login (Go to 2 if already exist in DB else go to 1.1)

1.1 - Create the initialized tables in the Database and then go to 2

2. Read the data from database (serverside) and send the results clientside.

3. A triggered Clientside function add all the values from serverside to the Element (Player) with setElementData.

setElementData(root,"temp.account",playerData.account) 

Right now can i use the getElementData(source,temp.account) both clientside and serverside ?

4. When the player quit i want to save datas to Database. (Serverside)

  
dbExec(connect,"UPDATE Player (account) VALUES ('"..getElementData(source,"temp.account").."') 
  
  
  
  
 

Is it correct ?

Thanks for your help.

Edited by Guest
Link to comment
Right now can i use the getElementData(source,temp.account) both clientside and serverside ?

4. When the player quit i want to save datas to Database. (Serverside)

  
dbExec(connect,"UPDATE Player (account) VALUES ('"..getElementData(source,"temp.account").."') 
  
  
  
  
 

Ofcourse you can use elementdatas client and server side.

But i would only set it on server side, so client can only get the element data and not set it ( preventing cheats).

and to your dbExec :

You should write it like that to prevent mysql injections:

  
local setacc = getElementData(source,"temp.account") 
dbExec(connect,"UPDATE Player SET account=?",setacc) 
  

Link to comment

If i've more arguments it will work like that ?

  
dbExec(connect,"UPDATE Player (mail,bDay,bMonth,bYear,level,VIP,welcomeText,achivementPoints,token,tokenbought) SET (mail=?,bDay=?,bMonth=?,bYear=?,level=?,VIP=?,welcomeText=?,achivementPoints=?,token=?,tokenBought=?) WHERE account = '"..quittingPlayerAccount.."'",mail,bDay,bMonth,bYear,level,VIP,welcomeText,achivementPoints,token,tokenbought) 
  

Thanks for your Help.

Link to comment

No.

  
  
dbExec(connect,"UPDATE Player SET mail=?,bDay=?,bMonth=?,bYear=?,level=?,VIP=?,welcomeText=?,achivementPoints=?,token=?,tokenBought=? WHERE account =?",mail,bDay,bMonth,bYear,level,VIP,welcomeText,achivementPoints,token,tokenbought,quittingPlayerAccount) 
  

Link to comment

It says it's not correct.

What is my error ?

  
dbExec(connect,"UPDATE Player (mail,bDay,bMonth,bYear,level,VIP,welcomeText,achivementPoints,token,tokenbought) SET mail=?,bDay=?,bMonth=?,bYear=?,level=?,VIP=?,welcomeText=?,achivementPoints=?,token=?,tokenBought=? WHERE account =?",mail,bDay,bMonth,bYear,level,VIP,welcomeText,achivementPoints,token,tokenbought,quittingPlayerAccount) 
  

Thanks.

Link to comment
  • Moderators
Hi all

I explain my situation. I'm creating an userpanel with MySQL Database.

Step By Step

1. When the player login (Go to 2 if already exist in DB else go to 1.1)

1.1 - Create the initialized tables in the Database and then go to 2

2. Read the data from database (serverside) and send the results clientside.

3. A triggered Clientside function add all the values from serverside to the Element (Player) with setElementData.

setElementData(root,"temp.account",playerData.account) 

Right now can i use the getElementData(source,temp.account) both clientside and serverside ?

Is it correct ?

Thanks for your help.

Almost, you have to use localPlayer instead of root to set the element data for the player. And yeah you will be able to use it on both sides. That being said, you can also set the element data for the player on the server side instead of triggering a client side function which will set the element data.

Link to comment

Its not working.

Error Message :

  
WARNING: @[gamemodes]/[race]/[addons]/panel/server.lua:75: dbExec fai 
led; (1064) You have an error in your SQL syntax; check the manual that correspo 
nds to your MySQL server version for the right syntax to use near 'account=0,mai 
l='none',bDay=0,bMonth='',bYear='',level='',VIP='',welcomeText='',a' at line 1 
  

Code :

  
dbExec(connect,"INSERT INTO Player VALUES account=?,mail=?,bDay=?,bMonth=?,bYear=?,level=?,VIP=?,welcomeText=?,achivementPoints=?,token=?,tokenbought=?",account,mail,bDay,bMonth,bYear,level,VIP,welcomeText,achivementPoints,token,tokenbought) 
  

What's wrong ?

Thanks.

Link to comment
dbExec(connect,"INSERT INTO Player ( account, mail, bDay, bMonth, bYear, level, VIP, welcomeText, achivementPoints, token, tokenbought ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )", account, mail, bDay, bMonth, bYear, level, VIP, welcomeText, achivementPoints, token, tokenbought) 

Link to comment

I've another problem now :-)

But count seems to be correct 0.o

Error :

  
[12:02:57] WARNING: @[gamemodes]/[race]/[addons]/panel/server.lua:75: dbExec fai 
led; (1136) Column count doesn't match value count at row 1 
  

Code :

  
dbExec(connect,"INSERT INTO Player VALUES (?,?,?,?,?,?,?,?,?,?,?)",account,mail,bDay,bMonth,bYear,level,VIP,welcomeText,achivementPoints,token,tokenbought) 
  

Thanks for your help.

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