Jump to content

[OK] set&getElementData and MySQL


Recommended Posts

Posted (edited)

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

430x73_67B2EB_F75151_000000_000000.png

430x73_67B2EB_F75151_000000_000000.png

  • Moderators
Posted

You will get problems with that, to prevent errors:

local theData = tostring(getElementData(source,"temp.account") or "") 

But the db, I can't help you want that.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
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) 
  

Posted

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.

430x73_67B2EB_F75151_000000_000000.png

430x73_67B2EB_F75151_000000_000000.png

Posted

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) 
  

Posted

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.

430x73_67B2EB_F75151_000000_000000.png

430x73_67B2EB_F75151_000000_000000.png

  • Moderators
Posted
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.

The rEvolution is coming ...

  • Moderators
Posted

No problem (If you want to avoid wrong answers from others, just post in the French sub-forum, I'm always available there ;))

The rEvolution is coming ...

Posted

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.

430x73_67B2EB_F75151_000000_000000.png

430x73_67B2EB_F75151_000000_000000.png

Posted
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) 

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

Posted

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.

430x73_67B2EB_F75151_000000_000000.png

430x73_67B2EB_F75151_000000_000000.png

Posted

i was give you the correct code. the code that you give back now it's incorrect

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

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